Home Backend Development PHP Tutorial Complete list and behavior description of regular expression metacharacters_PHP Tutorial

Complete list and behavior description of regular expression metacharacters_PHP Tutorial

Jul 20, 2016 am 11:15 AM
for list reverse character whole Will Quote text mark regular expression illustrate

Character

Description

Mark the next character as a special character, text, backreference, or octal escape. For example, "n" matches the character "n". "n" matches a newline character. Involves input characters . * + ? | ( ) { }^ $, which needs to be preceded, such as: the sequence "\" matches "", "(" matches "(".

^

Matches the beginning of the input string. If the Multiline property of a RegExp object is set, ^ will also match the position after "n" or "r".

$

Matches the end of the input string. If the Multiline property of the RegExp object is set, $ will also match the position before "n" or "r".

*

Matches the preceding character or subexpression zero or more times. For example, zo* matches "z" and "zoo". * Equivalent to {0,}.

+

Matches the preceding character or subexpression one or more times. For example, "zo+" matches "zo" and "zoo" but not "z". + Equivalent to {1,}.

?

Matches the preceding character or subexpression zero or once times. For example, "do(es)?" matches the "do" in "do" or "does". ? Equivalent to {0,1}.

{n}

n is a non-negative integer. Matches exactly n times. For example, "o{2}" does not match the "o" in "Bob" but does match both "o"s in "food".

{n,}

n is a non-negative integer. Match at least n times. For example, "o{2,}" does not match the "o" in "Bob" but matches all o's in "foooood". "o{1,}" is equivalent to "o+". "o{0,}" is equivalent to "o*".

{n,m}

M and n are non-negative integers, where n <= m. Match at least n times and at most m times. For example, "o{1,3}" matches the first three o's in "fooooood". 'o{0,1}' is equivalent to 'o?'. Note: You cannot insert spaces between commas and numbers.

?

When this character is followed by any other qualifier (*, +, ?, {n}, {n,}, {n,m}), the matching pattern is "non-greedy". The "non-greedy" pattern matches the shortest possible string that is searched for, while the default "greedy" pattern matches the longest possible string that is searched for. For example, in the string "oooo", "o+?" matches only a single "o", while "o+" matches all "o"s.

.

Matches any single character except "n". To match any character including "n", use a pattern such as "[sS]".

(pattern)

matches pattern and captures the matching subexpression. Captured matches can be retrieved from the resulting "matches" collection using the $0…$9 attribute. To match the bracket character ( ), use "(" or ")".

(?:pattern)

matches pattern but does not capture the subexpression of that match, i.e. it is a non-capturing match and does not store the match for later use. This is useful when combining pattern parts with the "or" character (|). For example, 'industr(?:y|ies) is a more economical expression than 'industry|industries'.

(?=pattern)

A subexpression that performs a forward lookahead search that matches a string at the start of a string matching pattern. It is a non-capturing match, i.e. a match that cannot be captured for later use. For example, 'Windows (?=95|98|NT|2000)' matches 'Windows' in 'Windows 2000', but not 'Windows' in 'Windows 3.1'. Prediction lookaheads do not occupy characters, that is, after a match occurs, the next match is searched immediately after the previous match, not after the characters that make up the prediction lookahead.

(?!pattern)

A subexpression that performs a backward lookahead search that matches a search string that is not at the start of a string matching pattern. It is a non-capturing match, i.e. a match that cannot be captured for later use. For example, 'Windows (?!95|98|NT|2000)' matches 'Windows' in 'Windows 3.1', but not 'Windows' in 'Windows 2000'. Prediction lookaheads do not occupy characters, that is, after a match occurs, the next match is searched immediately after the previous match, not after the characters that make up the prediction lookahead.

x|y

matches x or y. For example, 'z|food' matches "z" or "food". '(z|f)ood' matches "zood" or "food".

[xyz]

Character set. Matches any character contained in . For example, "[abc]" matches the "a" in "plain".

[^xyz]

Reverse character set. Matches any characters not included. For example, "[^abc]" matches the "p" in "plain".

[a-z]

Character range. Matches any character within the specified range. For example, "[a-z]" matches any lowercase letter in the range "a" through "z".

[^a-z]

Reverse range character. Matches any character not within the specified range. For example, "[^a-z]" matches any character that is not in the range "a" through "z".

b

matches a word boundary, that is, the position (including the starting and ending positions) between the word and a space (or punctuation mark - ASCII standard characters except letters and numbers can generally be understood as punctuation marks). For example, "erb" matches the "er" in "never" but not the "er" in "verb".

B

Non-word boundary matching. "erB" matches the "er" in "verb", but not the "er" in "never".

cx

matches the control character indicated by x. For example, cM matches Control-M or carriage return. The value of x must be between A-Z or a-z. If this is not the case, c is assumed to be the "c" character itself.

d

Number character matching. Equivalent to [0-9].

D

Non-numeric character matching. Equivalent to [^0-9].

f

Form break matching. Equivalent to x0c and cL.

n

Newline matching. Equivalent to x0a and cJ.

r

matches a carriage return character. Equivalent to x0d and cM.

s

Matches any whitespace character, including spaces, tabs, form feeds, etc. Equivalent to [ fnrtv].

S

matches any non-whitespace character. Equivalent to [^ fnrtv].

t

Tab matching. Equivalent to x09 and cI.

v

Vertical tab matching. Equivalent to x0b and cK.

w

Matches any type character, including underscore. Equivalent to "[A-Za-z0-9_]".

W

matches any non-word character. Equivalent to "[^A-Za-z0-9_]".

xn

matches n, where n is a hexadecimal escape code. The hexadecimal escape code must be exactly two digits long. For example, "x41" matches "A". "x041" is equivalent to "x04" & "1". Allow ASCII codes in regular expressions.

num

matches num, where num is a positive integer. Backreference to capture match. For example, "(.)1" matches two consecutive identical characters.

n

Identifies an octal escape code or backreference. If n is preceded by at least n capturing subexpressions, then n is a backreference. Otherwise, if n is an octal number (0-7), then n is an octal escape code.

nm

Identifies an octal escape code or backreference. If nm is preceded by at least nm capturing subexpressions, then nm is a backreference. If nm is preceded by at least n captures, then n is a backreference followed by the characters m. If neither of the previous conditions exists, then nm matches the octal value nm, where n and m are octal digits (0 -7).

nml

When n is an octal number (0-3), m and l are octal numbers (0-7), match the octal escape code nml.

un

matches n, where n is a Unicode character represented as a four-digit hexadecimal number. For example, u00A9 matches the copyright symbol (©).

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440178.htmlTechArticleCharacter Description Marks the next character as a special character, text, backreference, or octal escape character. For example, n matches the character n. n matches newlines. Involves input characters . * + ? | ( )...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to mark minesweeper? -How to change the difficulty of Minesweeper? How to mark minesweeper? -How to change the difficulty of Minesweeper? Mar 18, 2024 pm 06:34 PM

How to mark minesweeper? First, we need to familiarize ourselves with the marking method in Minesweeper. Normally, there are two common marking methods in Minesweeper games: flag marking and question mark marking. The flag mark is used to indicate that there are mines in the block and is a deterministic mark; while the question mark mark indicates that there may be mines in the block, but it is not deterministic. These two marking methods play an important role in the game, helping players to infer which blocks may contain mines, so as to effectively proceed to the next step. Proficient use of these marking methods can improve the player's success rate in the minesweeper game and reduce the risk of stepping on mines. Therefore, when playing the minesweeper game, if the player has mastered the flag mark and question mark mark, when the player is not sure whether there is a mine in a certain square, he can use the question mark mark to mark it.

How to count the number of elements in a list using Python's count() function How to count the number of elements in a list using Python's count() function Nov 18, 2023 pm 02:53 PM

How to use Python's count() function to calculate the number of an element in a list requires specific code examples. As a powerful and easy-to-learn programming language, Python provides many built-in functions to handle different data structures. One of them is the count() function, which can be used to count the number of elements in a list. In this article, we will explain how to use the count() function in detail and provide specific code examples. The count() function is a built-in function of Python, used to calculate a certain

How to use block quotes in Apple Notes How to use block quotes in Apple Notes Oct 12, 2023 pm 11:49 PM

In iOS 17 and macOS Sonoma, Apple has added new formatting options for Apple Notes, including block quotes and a new Monostyle style. Here's how to use them. With additional formatting options in Apple Notes, you can now add block quotes to your notes. The block quote format makes it easy to visually offset sections of writing using the quote bar to the left of the text. Just tap/click the "Aa" format button and select the block quote option before typing or when you are on the line you want to convert to a block quote. This option applies to all text types, style options, and lists, including checklists. In the same Format menu you can find the new Single Style option. This is a revision of the previous "equal-width"

How to mark multiple locations on Baidu Maps How to mark multiple locations How to mark multiple locations on Baidu Maps How to mark multiple locations Mar 15, 2024 pm 04:28 PM

There are many functions above, especially for maps that can mark multiple places. When we know some places, we will definitely use some punctuation functions, so that we can bring you a variety of different aspects. Some of the functions you mark will produce distance differences, that is, you can know how far away they are. Of course, some names and detailed information of the above places will also be displayed. However, many netizens may not be familiar with some of the above. The content information is not very clear, so in order to allow everyone to make better choices in various aspects, today the editor will bring you some choices in various aspects, so friends who are interested in ideas, If you are also interested, come and give it a try. Standard

How to search for text across all tabs in Chrome and Edge How to search for text across all tabs in Chrome and Edge Feb 19, 2024 am 11:30 AM

This tutorial shows you how to find specific text or phrases on all open tabs in Chrome or Edge on Windows. Is there a way to do a text search on all open tabs in Chrome? Yes, you can use a free external web extension in Chrome to perform text searches on all open tabs without having to switch tabs manually. Some extensions like TabSearch and Ctrl-FPlus can help you achieve this easily. How to search text across all tabs in Google Chrome? Ctrl-FPlus is a free extension that makes it easy for users to search for a specific word, phrase or text across all tabs of their browser window. This expansion

How to create a grocery list: Use the Reminders app for iPhone How to create a grocery list: Use the Reminders app for iPhone Dec 01, 2023 pm 03:37 PM

In iOS 17, Apple added a handy little list feature to the Reminders app to help you when you're out shopping for groceries. Read on to learn how to use it and shorten your trip to the store. When you create a list using the new "Grocery" list type (named "Shopping" outside the US), you can enter a variety of food and groceries and have them automatically organized by category. This organization makes it easier to find what you need at the grocery store or while out shopping. Category types available in alerts include Produce, Bread & Cereals, Frozen Foods, Snacks & Candy, Meat, Dairy, Eggs & Cheese, Baked Goods, Baked Goods, Household Products, Personal Care & Wellness, and Wine, Beer & Spirits . The following is created in iOS17

Try new ringtones and text tones: Experience the latest sound alerts on iPhone in iOS 17 Try new ringtones and text tones: Experience the latest sound alerts on iPhone in iOS 17 Oct 12, 2023 pm 11:41 PM

In iOS 17, Apple has overhauled its entire selection of ringtones and text tones, offering more than 20 new sounds that can be used for calls, text messages, alarms, and more. Here's how to see them. Many new ringtones are longer and sound more modern than older ringtones. They include arpeggio, broken, canopy, cabin, chirp, dawn, departure, dolop, journey, kettle, mercury, galaxy, quad, radial, scavenger, seedling, shelter, sprinkle, steps, story time , tease, tilt, unfold and valley. Reflection remains the default ringtone option. There are also 10+ new text tones available for incoming text messages, voicemails, incoming mail alerts, reminder alerts, and more. To access new ringtones and text tones, first, make sure your iPhone

How to Make a Shopping List in the iOS 17 Reminders App on iPhone How to Make a Shopping List in the iOS 17 Reminders App on iPhone Sep 21, 2023 pm 06:41 PM

How to Make a GroceryList on iPhone in iOS17 Creating a GroceryList in the Reminders app is very simple. You just add a list and populate it with your items. The app automatically sorts your items into categories, and you can even work with your partner or flat partner to make a list of what you need to buy from the store. Here are the full steps to do this: Step 1: Turn on iCloud Reminders As strange as it sounds, Apple says you need to enable reminders from iCloud to create a GroceryList on iOS17. Here are the steps for it: Go to the Settings app on your iPhone and tap [your name]. Next, select i

See all articles