Skip to content

Commit 6843534

Browse files
committed
Migrate C# code
1 parent 9511f82 commit 6843534

File tree

2 files changed

+364
-17
lines changed

2 files changed

+364
-17
lines changed

docs/standard/base-types/character-classes-in-regular-expressions.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Some common regular expression patterns that contain positive character classes
7777

7878
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.
7979

80-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#1](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/positivecharclasses.cs#1)]
80+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="PositiveCharacterGroup":::
8181
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#1](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/positivecharclasses.vb#1)]
8282

8383
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
9292

9393
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.
9494

95-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#3](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/range.cs#3)]
95+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="CharacterRange":::
9696
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/range.vb#3)]
9797

9898
The regular expression `\b[A-Z]\w*\b` is defined as shown in the following table.
@@ -141,7 +141,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
141141

142142
The following example matches any word that begins with the characters "th" and is not followed by an "o".
143143

144-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#2](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/negativecharclasses.cs#2)]
144+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="NegativeCharacterGroup":::
145145
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/negativecharclasses.vb#2)]
146146

147147
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
164164

165165
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`.
166166

167-
[!code-csharp[Conceptual.Regex.Language.CharacterClasses#5](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/any2.cs#5)]
167+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="AnyCharacterMultiline":::
168168
[!code-vb[Conceptual.Regex.Language.CharacterClasses#5](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/any2.vb#5)]
169169

170170
> [!NOTE]
171171
> Because it matches any character except `\n`, the `.` character class also matches `\r` (the carriage return character).
172172
173173
- 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.
174174

175-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#4](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/any1.cs#4)]
175+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="AnyCharacterSingleline":::
176176
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/any1.vb#4)]
177177

178178
> [!NOTE]
@@ -195,7 +195,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
195195
196196
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).
197197

198-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#6](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/category1.cs#6)]
198+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="UnicodeCategory":::
199199
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#6](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/category1.vb#6)]
200200

201201
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
229229
230230
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.
231231

232-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#7](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/notcategory1.cs#7)]
232+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="NegativeUnicodeCategory":::
233233
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#7](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/notcategory1.vb#7)]
234234

235235
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
263263
|(\w)|Match a word character. This is the first capturing group.|
264264
|\1|Match the value of the first capture.|
265265

266-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#8](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/wordchar1.cs#8)]
266+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="WordCharacter":::
267267
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#8](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/wordchar1.vb#8)]
268268

269269
<a name="NonWordCharacter"></a>
@@ -300,7 +300,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
300300
|(\w+)|Match one or more word characters. This is the first capturing group.|
301301
|(\W){1,2}|Match a non-word character either one or two times. This is the second capturing group.|
302302

303-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#9](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/nonwordchar1.cs#9)]
303+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="NonWordCharacter":::
304304
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#9](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/nonwordchar1.vb#9)]
305305

306306
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
333333
|s|Match an "s".|
334334
|(\s&#124;$)|Match either a white-space character or the end of the input string.|
335335

336-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#10](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/whitespace1.cs#10)]
336+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="WhitespaceCharacter":::
337337
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#10](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/whitespace1.vb#10)]
338338

339339
<a name="NonWhitespaceCharacter"></a>
@@ -352,7 +352,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
352352
|`(\S+)`|Match one or more non-white-space characters. This is the first capturing group.|
353353
|`\s?`|Match zero or one white-space character.|
354354

355-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#11](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/nonwhitespace1.cs#11)]
355+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="NonWhitespaceCharacter":::
356356
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#11](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/nonwhitespace1.vb#11)]
357357

358358
<a name="DigitCharacter"></a>
@@ -376,7 +376,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
376376
|`\d{3}-\d{4}`|Match three decimal digits followed by a hyphen and four more decimal digits.|
377377
|`$`|Match the end of the input string.|
378378

379-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#12](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/digit1.cs#12)]
379+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="DigitCharacter":::
380380
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#12](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/digit1.vb#12)]
381381

382382
<a name="NonDigitCharacter"></a>
@@ -397,7 +397,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
397397
|`\D*`|Match zero, one, or more non-decimal characters.|
398398
|`$`|Match the end of the input string.|
399399

400-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#13](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/nondigit1.cs#13)]
400+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="NonDigitCharacter":::
401401
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#13](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/nondigit1.vb#13)]
402402

403403
<a name="SupportedUnicodeGeneralCategories"></a>
@@ -448,7 +448,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
448448

449449
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.
450450

451-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#14](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/getunicodecategory1.cs#14)]
451+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="GetUnicodeCategory":::
452452
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#14](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/getunicodecategory1.vb#14)]
453453

454454
<a name="SupportedNamedBlocks"></a>
@@ -593,7 +593,7 @@ where *firstCharacter* is the character that begins the range and *lastCharacter
593593
|`[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.|
594594
|$|End the match at the end of the input string.|
595595

596-
[!code-csharp[Conceptual.RegEx.Language.CharacterClasses#15](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.regex.language.characterclasses/cs/classsubtraction1.cs#15)]
596+
:::code language="csharp" source="snippets/character-classes-in-regular-expressions/csharp/Program.cs" id="CharacterClassSubtraction":::
597597
[!code-vb[Conceptual.RegEx.Language.CharacterClasses#15](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.regex.language.characterclasses/vb/classsubtraction1.vb#15)]
598598

599599
## See also

0 commit comments

Comments
 (0)