-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Ported as conceptual article from .NET dev blog: Regex enhancements with .NET 7
#31587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6557c80
Initial bits and raw port
IEvangelist 5b944f0
Added to TOC
IEvangelist d2db91e
Fix syntax error
IEvangelist bd3feaf
Minor updates and tweaks
IEvangelist 9d4cbbd
Minor update
IEvangelist e7527ae
Updates, removals, clean up
IEvangelist 7920798
Fix names and paths
IEvangelist 4036506
Updates and fixes
IEvangelist 5e1f665
More updates and clean up
IEvangelist 720ee02
Getting close
IEvangelist 2670e0d
More fixes and updates, and adjusted headings
IEvangelist 19e58bd
Finishing touches
IEvangelist 10cb957
A bit more clean up
IEvangelist 0ef7bb1
Testing footnote extensions
IEvangelist 92ef685
Testing diagram extensions
IEvangelist 0b7ed08
Testing definition list support with markdig exts
IEvangelist 87c594e
Add another footnote and code updates
IEvangelist f8e95aa
Ready for review
IEvangelist 53f3e05
Apply suggestions from code review
IEvangelist 882d1c1
Address additional feedback
IEvangelist 8b67a70
A bit of MD cleanup
IEvangelist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+60.6 KB
...e-types/media/regular-expression-source-generators/cached-instance-fallback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+60 KB
...ndard/base-types/media/regular-expression-source-generators/cached-instance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+444 KB
...-types/media/regular-expression-source-generators/convert-to-regexgenerator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+353 KB
...ard/base-types/media/regular-expression-source-generators/debuggable-source.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+404 KB
...standard/base-types/media/regular-expression-source-generators/xml-comments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
400 changes: 400 additions & 0 deletions
400
docs/standard/base-types/regular-expression-source-generators.md
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
docs/standard/base-types/snippets/regular-expression-source-generators/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| using System.Text; | ||
| using System.Text.RegularExpressions; | ||
|
|
||
| static partial class Program | ||
| { | ||
| private static readonly Regex s_abcOrDefGeneratedRegex = AbcOrDefGeneratedRegex(); | ||
|
|
||
| [GeneratedRegex( | ||
| pattern: "abc|def", | ||
| options: RegexOptions.IgnoreCase | RegexOptions.Compiled, | ||
| cultureName: "en-US")] | ||
| private static partial Regex AbcOrDefGeneratedRegex(); | ||
|
|
||
| private static void EvaluateText(string text) | ||
| { | ||
| if (s_abcOrDefGeneratedRegex.IsMatch(text)) | ||
| { | ||
| Console.WriteLine($""" | ||
| ✅ "{text}" matches "{s_abcOrDefGeneratedRegex}" pattern. | ||
| """); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine($""" | ||
| ❌ "{text}" doesn't match "{s_abcOrDefGeneratedRegex}" pattern. | ||
| """); | ||
| } | ||
| } | ||
|
|
||
| private static void Main() | ||
| { | ||
| Console.OutputEncoding = Encoding.UTF8; | ||
|
|
||
| new List<string> { "Incubus", "Deftones", "Tool" }.ForEach(EvaluateText); | ||
|
|
||
| // Sample output: | ||
| // ❌ "Incubus" doesn't match "abc|def" pattern. | ||
| // ✅ "Deftones" matches "abc|def" pattern. | ||
| // ❌ "Tool" doesn't match "abc|def" pattern. | ||
|
|
||
| var abcOrDefRegex = new Regex(pattern: "abc|def", options: RegexOptions.IgnoreCase); | ||
| } | ||
| } | ||
|
|
||
| static file partial class Program | ||
| { | ||
| [GeneratedRegex(pattern: @"(a|bc)d")] | ||
| private static partial Regex ExampleRegex(); | ||
|
|
||
| [GeneratedRegex(pattern: "[ab]*[bc]")] | ||
| private static partial Regex AnotherExampleRegex(); | ||
|
|
||
| [GeneratedRegex(pattern: "Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday")] | ||
| private static partial Regex DaysOfWeekRegex(); | ||
|
|
||
| [GeneratedRegex(pattern: "")] | ||
| private static partial Regex BlankRegex(); | ||
|
|
||
| [GeneratedRegex(pattern: @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")] | ||
| private static partial Regex EmailRegex(); | ||
|
|
||
| [GeneratedRegex(pattern: "(\\w)\\1")] | ||
| private static partial Regex WordWithBacktrackingRegex(); | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
docs/standard/base-types/snippets/regular-expression-source-generators/regex.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.