The usage of C # regular expression Regex class
This article mainly introduces "the usage of C# regular expression Regex class". In daily operation, I believe that many people have doubts about the usage of C# regular expression Regex class. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the usage of C# regular expression Regex class". Next, please follow the editor to study!
The Regex class represents an immutable (read-only) regular expression. It also contains a variety of static methods that allow you to use other regular expression classes without explicitly creating instances of other classes.
Overview of the basics of regular expressions
What is a regular expression
When writing string handlers, there is often a need to find strings that conform to some complex rules. Regular expressions are the tools used to describe these rules. In other words, a regular expression is the code that records text rules.
Typically, when we use WINDOWS to find files, we use wildcards (* and?). If you want to find all the Word documents in a directory, you can use * .doc to find it, where * is interpreted as any string. Like wildcards, regular expressions are a tool for text matching, except that they describe your requirements more accurately than wildcards-at the expense of being more complex.
I. C # regular expression symbol pattern
Character character
Description
\
Escape character, escape a character with a special function into a normal character, or vice versa
^
Match the starting position of the input string
$
Matches the end position of the input string
*
Matches the previous zero or more subexpressions
+
Matches the previous one or more subexpressions
?
Matches the previous zero or once subexpression
{n}
N is a non-negative integer that matches the previous n-th subexpression.
{n,}
N is a non-negative integer that matches at least the previous n-th subexpression.
{n,m}
M and n are non-negative integers, where n