SoFunction
Updated on 2025-03-07

c# regular guideline-character group

Character group: Various characters that may appear in the same seat.
Use regular expressions to determine numeric characters:

("[0123456789]",charStr) != None

Where [0123456789] gives a regular expression in the form of a string, which is a character group, indicating that it can be any character from 0 to 9.
in Net(charStr,"[0123456789]");
By default, Search(Pattern,String) will only judge whether a substring can match the pattern. As long as the pattern can match part of the String, it is also considered successful. In order to test whether the entire String can match the pattern, ^ and $ must be added to both ends of the pattern. They represent the starting and end positions of the string, so that it can be guaranteed that only if the entire String can be matched by the pattern, it is considered successful.
For example, this character group [0123456789] can also use range notation: [0-9]

In the character group: "-" represents a range. Generally, according to a code value corresponding to the character, the small code value is in front of "-" and the large one is in the back.
In the above example, "-" is used to represent the range and cannot match horizontal characters. This type of character is called metacharacter, such as [,], ^, and $ are all metacharacters.

Then when we need to match these special metacharacters, we need to escape.
For example, if the character "-" is next to "[", it will be considered an ordinary character. In other cases, all metacharacters are metacharacters. You can use "\" to escape the metacharacters:
("^[0\\-9]$","3") != None //false
The above "\" character itself will be used in conjunction with other such as "\n \r", etc., and "\\" is also required to escape if used alone.
Use the native string: (r"^[0\-9]$","3") != None , prefix the string with r. You can no longer use "\\" to mean "\".
Excluded character group: [^...]: indicates the current position, matching a character that is not listed.
[^0-9]: means matching a character that is not a number
Character group abbreviation method:
Common ones are:

\d:[0-9]
\w: [0-9a-zA-Z] This also includes an underscore
\s:[ \t\r\n\v\f]

Corresponding exclusion character group abbreviation method:
\D : Complementary with \d
\W : Complementary with \w
\S: Complementary with \s
The easiest application: [\s\S] combined to match all characters.