You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/standard/base-types/character-classes-in-regular-expressions.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ Some common regular expression patterns that contain positive character classes
77
77
78
78
The following example defines a positive character group that contains the characters "a" and "e" so that the input string must contain the words "grey" or "gray" followed by another word for a match to occur.
The regular expression `gr[ae]y\s\S+?[\s|\p{P}]` is defined as follows:
@@ -92,7 +92,7 @@ Some common regular expression patterns that contain positive character classes
92
92
93
93
The following example matches words that begin with any capital letter. It uses the subexpression `[A-Z]` to represent the range of capital letters from A to Z.
The regular expression `\bth[^o]\w+\b` is defined as shown in the following table.
@@ -164,15 +164,15 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
164
164
165
165
The following example illustrates the different behavior of the `.` character class by default and with the <xref:System.Text.RegularExpressions.RegexOptions.Singleline?displayProperty=nameWithType> option. The regular expression `^.+` starts at the beginning of the string and matches every character. By default, the match ends at the end of the first line; the regular expression pattern matches the carriage return character, `\r`, but it does not match `\n`. Because the <xref:System.Text.RegularExpressions.RegexOptions.Singleline?displayProperty=nameWithType> option interprets the entire input string as a single line, it matches every character in the input string, including `\n`.
> Because it matches any character except `\n`, the `.` character class also matches `\r` (the carriage return character).
172
172
173
173
- In a positive or negative character group, a period is treated as a literal period character, and not as a character class. For more information, see [Positive Character Group](#PositiveGroup) and [Negative Character Group](#NegativeGroup) earlier in this topic. The following example provides an illustration by defining a regular expression that includes the period character (`.`) both as a character class and as a member of a positive character group. The regular expression `\b.*[.?!;:](\s|\z)` begins at a word boundary, matches any character until it encounters one of five punctuation marks, including a period, and then matches either a white-space character or the end of the string.
@@ -195,7 +195,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
195
195
196
196
The following example uses the `\p{`*name*`}` construct to match both a Unicode general category (in this case, the `Pd`, or Punctuation, Dash category) and a named block (the `IsGreek` and `IsBasicLatin` named blocks).
The regular expression `\b(\p{IsGreek}+(\s)?)+\p{Pd}\s(\p{IsBasicLatin}+(\s)?)+` is defined as shown in the following table.
@@ -229,7 +229,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
229
229
230
230
The following example uses the `\P{`*name*`}` construct to remove any currency symbols (in this case, the `Sc`, or Symbol, Currency category) from numeric strings.
The regular expression pattern `(\P{Sc})+` matches one or more characters that are not currency symbols; it effectively strips any currency symbol from the result string.
@@ -263,7 +263,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
263
263
|(\w)|Match a word character. This is the first capturing group.|
Because the <xref:System.Text.RegularExpressions.Group> object for the second capturing group contains only a single captured non-word character, the example retrieves all captured non-word characters from the <xref:System.Text.RegularExpressions.CaptureCollection> object that is returned by the <xref:System.Text.RegularExpressions.Group.Captures%2A?displayProperty=nameWithType> property.
@@ -333,7 +333,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
333
333
|s|Match an "s".|
334
334
|(\s|$)|Match either a white-space character or the end of the input string.|
@@ -448,7 +448,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
448
448
449
449
You can determine the Unicode category of any particular character by passing that character to the <xref:System.Char.GetUnicodeCategory%2A> method. The following example uses the <xref:System.Char.GetUnicodeCategory%2A> method to determine the category of each element in an array that contains selected Latin characters.
@@ -593,7 +593,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
593
593
|`[0-9-[2468]]+`|Match one or more occurrences of any character from 0 to 9 except for 2, 4, 6, and 8. In other words, match one or more occurrences of zero or an odd digit.|
0 commit comments