Regular Expressions.regex

Source: Internet
Author: User

See some tutorials on the web

The namespace required for the regular is the using System.Text.RegularExpressions

Regex can be used not only to create regular expressions, but also to provide a number of useful methods

The first is some syntax with matching characters:

the basic syntax character.
Number of/D 0-9
The complement of the/d/d (so that the word identifier complete, the same as the same), that is, all non-numeric characters
/w word character, refers to uppercase and lowercase letters, 0-9 digits, underscores
The complement of/w/w
/s white space character, including line break/n, carriage return/R, Tab/T, vertical tab/V, page break/F
The complement of/S/S
. Any character other than the line break/n
[...] Match all the characters listed in []
[^ ...] Match characters that are not listed in []

Positioning characters
The "anchor character" represents a virtual character, which represents a location, and you can intuitively assume that the "anchor character" represents the tiny gap between a character and a character.
^ indicates that subsequent characters must be at the beginning of the string
$ indicates that the preceding character must be at the end of the string
/b matches the boundary of a word
/b matches a non-word boundary
Also, include:/A before the character must be at the beginning of the character,/z before the character must be at the end of the string,/z before the character must be at the end of the string, or in front of the newline character

Repeating description characters
The repeating description character is one of the places where C # regular expressions are "very good and powerful":
{n} matches the preceding character n times
{N,} matches the preceding character n times or more than n times
{n,m} matches the preceding characters n to M times
? Matches the preceding character 0 or 1 times
+ Match previous characters 1 or more 1 times
* match the preceding character 0 times or 0 times

Regular expression modifiers

I: If you add "I" to the modifier, the regular will remove the case sensitivity, i.e. "a" and "a" are the same.
M: Default regular start "^" and end "$" just for regular strings if you add "M" to the modifier, then the start and end will refer to each line of the string: the beginning of each line is "^" and the End is "$".
S: If "s" is added to the modifier, then the default "." Any character that represents anything other than a newline character will become any characters, including line breaks!
x: If the modifier is added, the white space character in the expression will be ignored unless it has been escaped.
E: This modifier is only useful for replacement, and represents the PHP code in replacement.
A: If you use this modifier, the expression must be the beginning of the matching string. For example, "/a/a" matches "ABCD".
E: In contrast to "M", if this modifier is used, then "$" will match the end of the absolute string, not the line break, which is turned on by default.
U: Similar to question mark, used to set "greedy mode".

Finally: The program has been error AH = = So I handed it in first, next time change AH

Regular Expressions.regex

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.