Regular Expression metacharacters

Source: Internet
Author: User
Tags character classes

& L

Basic metacharacters

Metacharacters Description
. Match any single character
| Logic or operator
[] Define a character set combination to match one character in the Set
[^] Evaluate the non-union of character sets (the non-union of the entire set, rather than the character next to the ^ symbol)
- Define a range in the character set. For example, [A-Za-Z]
/ Escape the next character. For example,/n indicates line feed.

 

 

 

 

 

 

 

 

 

 

 

Number of metacharacters

Metacharacters Description
* Matches the previous character (subexpression) zero or multiple times
*? * Lazy version (to prevent regular expressions from being "greedy ")
+ Match the previous character or subexpression once or multiple times
+? + Lazy version
? Matches the first character or subexpression zero or once
{N} Match n times of the previous character or subexpression, for example, [A-Z] {6} indicates matching a string consisting of six uppercase letters.
{M, n}

T;/td>
Match at least m times and at most n times
{M ,} Match at least m times
{M ,}? {M,} lazy version

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Location metacharacters

Metacharacters Description
^ Beginning of Line
$ End of line
/< Start with a word
/> Word end
/B Word boundary (start and end of a word)
/B /B.

 

 

 

 

 

 

 

 

 

 

 

Special metacharacters

Metacharacters Description
[/B] Match a space character
/C Match A Control Character
/D Match any number character, equivalent to [0-9]
/D /D.
/F Page feed
/N Line Break
/R Carriage Return
/S Match a blank character
/S /S.
/T Tab
/V Vertical Tab
/W Match any letter, number, or underline. Equivalent to [A-Za-z0-9 _]
/W /W.
/X Matches a hexadecimal number.
/0 Matches an octal number.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Retrospective reference and search

Metacharacters Description
() Define a subexpression
/1 The first subexpression. Similarly,/2 indicates 2nd subexpressions. /0 usually indicates the entire regular expression.
? = Forward lookup
? <= Backward Search
?! Negative forward lookup
?! = Negative backward Lookup
? () Condition (if then)
? () | Condition (if then else)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

In addition,/e,/L,/L,/U, and so on indicate case-insensitive conversion. (? M) indicates that the regular expression is matched using the branch matching mode. All of the above are tested using the preg series functions in PHP. For special metacharacters, there are also POSIX character classes: [: alnum:], [: Alpha:], [: cntrl:], [: digit:], [: graph:], [: blank:], [: lower:], [: Print:], [: punct:], [: Space:], [: Upper:], [: xdigit:]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.