Regular Expression Summary

Source: Internet
Author: User

A regular expression is used to operate strings;
1.: match any single character except \ n, and space match, but note that a point only matches one character (Chinese characters are also counted );
When there is a line feed:
A) Single Row mode:. can match \ n;
Single Row mode in vs: Regex. Matches/Match ("", "", RegexOptions. Singleline );
B) regular expression at the line feed: [\ s \ S], that is, space or non-space;
2. []: match any character in the brackets. B [aeiou] g, B [a-zA-Z] g. Note that the brackets also match only one character;
3. |: In Front Of or behind a vertical line
Z | food: z or food;
(Z | f) ood: zood or food;
*: Matches up to 0 subexpressions before it. It has nothing to do with the wildcard. For example, the regular expression "zo *" (equivalent to z (o) *) can match "z", "zo", and "zoo". Therefore, ". * "means that any string can be matched. "Z (B | c) *" → zb, zbc, zcb, zccc, zbbbccc. "Z (AB) *" can match z, zab, and zabab (use parentheses to change the priority ).
+: Match the previous subexpression once or multiple times, and compare it with * (0 to multiple times ). For example, the regular expression 9 + matches 9, 99, and 999. "Zo +" can match "zo" and "zoo", but cannot match "z ".
? : Match the previous subexpression zero or one time. For example, "do (es )?" It can match "do" or "does ". It is generally used to match "optional parts ". (Stop greedy Mode)
{N}: match the specified n times. "Zo {2}" → zoo. For example, "e {2}" cannot match "e" in "bed", but can match two "e" in "seed ". // Seeeed, no.
{N ,}: match at least n times. For example, "e {2,}" cannot match "e" in "bed", but can match all "e" in "seeeeeeeed ".

{N, m}: matches at least n times and at most m times. "E {}" will match the first three "e" in "seeeeeeeed ". {2, 5} // bed, seed, seeed; beeeeed error.
Qualifier: specifies the number of occurrences of the regular expression.
^ (Shift + 6): match the beginning of a row. For example, the regular expression "^ regex" can match the start of the string "regex I will use", but cannot match "I will use regex ".
^ Another meaning: Not! ([^ 0-9]) in brackets, it indicates not
$: Match the row Terminator. For example, the regular expression "floating cloud $" can match the end of the string "Everything is floating cloud", but cannot match the string "floating cloud"

\ D: represents a number, equivalent to [0-9] <\ d> → \ d
\ D: represents a non-number, equivalent to [^ 0-9]
\ S: blank characters such as line breaks and Tab tabs (space, carriage return, and Tab)
(. Cannot match \ n)
\ S: Non-blank characters (a0% $ @@).
\ W: matches letters, numbers, underscores, or Chinese characters. It can be a word character, except % &#@! $ And other characters. [A-zA-Z0-9 _ Chinese characters]
\ W: not \ w, equivalent to [^ \ w] %
D: digital; s: space, w: word. Uppercase is "not"
 
Regular Expression in. net:
The main class of a Regular Expression (Regular Expression): Regex
Three common cases: (C # syntax)
Determine whether to match: Regex. IsMatch ("string", "Regular Expression ");
String extraction: Regex. Match ("string", "Regular Expression of the string to be extracted"); // only one can be extracted (extracted once)
String extraction (loop extraction of all): Regex. Matches (), (all matching strings can be extracted .)
String replacement: Regex. Replace ("string", "regular", "replacement content ");

Note: Two double quotation marks can be converted into one double quotation mark;

Related Article

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.