Вы находитесь на странице: 1из 3

CHARACTER CLASSES GROUPS

.NET
Use To match character Use To define
FRAMEWORK \ In that Unicode category or block (exp) Indexed group
REGULAR EXPRESSIONS p{ctgry} (? Named group
\ Not in that Unicode category or <name>exp)
SINGLE CHARACTERS P{ctgry} block (?<name1- Balancing group
\w Word character name2>exp)
Use To match any character \W Non-word character (?:exp) Noncapturing group
[set] In that set \d Decimal digit (?=exp) Zero-width positive
[^set] Not in that set \D Not a decimal digit lookahead
[a–z] In the a-z range \s White-space character (?!exp) Zero-width negative
[^a–z] Not in the a-z range \S Non-white-space char lookahead
. Any except \n (new line) (?<=exp) Zero-width positive
\char Escaped special character QUANTIFIERS lookbehind
(?<!exp) Zero-width negative
CONTROL CHARACTERS Greedy Lazy Matches lookbehind
Use To match Unicode * *? 0 or more times (?>exp) Non-backtracking (greedy)
+ +? 1 or more times
\t Horizontal tab \u0009
? ?? 0 or 1 time INLINE OPTIONS
\v Vertical tab \u000B
{n} {n}? Exactly n times
\b Backspace \u0008 Option Effect on match
{n,} {n,}? At least n times
\e Escape \u001B i Case-insensitive
{n,m} {n,m}? From n to m times
\r Carriage return \u000D m Multiline mode
\f Form feed \u000C n Explicit (named)
\n New line \u000A ANCHORS s Single-line mode
\a Bell (alarm) \u0007 Use To specify position x Ignore white space
\c char ASCII control  ^ At start of string or line
character \A At start of string Use To
\z At end of string (?imnsx- Set or disable the specified
NON-ASCII CODES
\Z At end (or before \n at end) of string imnsx) options
Use To match character with $ At end (or before \n at end) of string (?imnsx- Set or disable the specified
\octal 2-3 digit octal character code or line imnsx:exp) options within the
\x hex 2-digit hex character code \G Where previous match ended expression
\u hex 4-digit hex character code \b On word boundary
\B Not on word boundary June 2014
 2014 Microsoft. All rights reserved.
BACKREFERENCES Category Description M Mark, all diacritic
Lu Letter, uppercase Nd Number, decimal digit
Use To match LI Letter, lowercase Nl Number, letterlike
\n Indexed group Lt Letter, title case No Number, other
\k<name> Named group Lm Letter, modifier N Number, all
Lo Letter, other Pc Punctuation, connector
ALTERNATION L Letter, all Pd Punctuation, dash
Mn Mark, nonspacing combining Ps Punctuation, opening mark
Use To match Mc Mark, spacing combining Pe Punctuation, closing mark
a |b Either a or b Me Mark, enclosing combining Pi Punctuation, initial quote mark
(?(exp) yes if exp is matched Pf Puntuation, final quote mark
yes | no) no if exp isn't matched Po Punctuation, other
P Punctuation, all
(?(name) yes if name is matched
Sm Symbol, math
yes | no) no if name isn't matched Sc Symbol, currency
Sk Symbol, modifier
SUBSTITUTION So Symbol, other
Use To substitute S Symbol, all
Zs Separator, space
$n Substring matched by group
Zl Separator, line
number n Zp Separator, paragraph
${name} Substring matched by group Z Separator, all
name Cc Control code
$$ Literal $ character Cf Format control character
$& Copy of whole match Cs Surrogate code point
$` Text before the match Co Private-use character
Cn Unassigned
$' Text after the match
C Control characters, all
$+ Last captured group
$_ Entire input string For named character set blocks (e.g., Cyrillic), search
for "supported named blocks" in the MSDN Library.
COMMENTS REGULAR EXPRESSION OPERATIONS
Use To Class: System.Text.RegularExpressions.Regex
(?# comment) Add inline comment Pattern matching with Regex objects
# Add x-mode comment To initialize with Use constructor
For detailed information and examples, see Regular exp Regex(String)
http://aka.ms/regex + options Regex(String, RegexOptions)
To test your regular expressions, see + time-out Regex(String, RegexOptions,
http://regexlib.com/RETester.aspx TimeSpan)
SUPPORTED UNICODE CATEGORIES Pattern matching with static methods
Use an overload of a method below to supply the
regular expression and the text you want to search.

Finding and replacing matched patterns


To Use method
Validate match Regex.IsMatch
Retrieve single Regex.Match (first)
match Match.NextMatch (next)
Retrieve all Regex.Matches
matches
Replace match Regex.Replace
Divide text Regex.Split
Handle char Regex.Escape
escapes Regex.Unescape
Getting info about regular expression patterns
To get Use Regex API
Group names GetGroupNames
GetGroupNameFromNumbe
r
Group numbers GetGroupNumbers
GetGroupNumberFromNam
e
Expression ToString
Options Options
Time-out MatchTimeOut
Cache size CacheSize
Direction RightToLeft

Вам также может понравиться