Regular Expressions APIs in C#
Learn string matching with a given pattern using regular expressions, and use quantifiers and boundaries to efficiently define these patterns.
Regular expressions API
The .NET framework provides a rich and comprehensive Regex
class, defined within the System.Text.RegularExpressions
namespace, to match patterns of text via regular expressions.
We can use the following using
statement to access the regular expressions API in our program:
using System.Text.RegularExpressions;
This System.Text.RegularExpressions
namespace contains the following useful classes and interfaces.
Useful Classes and Interfaces
Class or Interface | Description |
| It represents a compiled regular expression and performs various operations like pattern matching and replacing patterns on strings. |
| It represents the results of a single regular expression match. |
| It represents the results of multiple regular expression matches. |
| It represents a captured group within a |
| It represents a collection of |
| It represents a capturing group within a |
| It represents a collection of |
| It enumerates the options that can be set when compiling a regular expression. |
This section focuses on implementing regular expressions for various use cases using the Regex class in .NET.
Note: We use C# 3+, notably dynamic typing, to take full advantage of C#'s language features.
The Regex
class
Description
...Get hands-on with 1400+ tech skills courses.