Character group: various characters that may appear in the same seat.
Use a regular expression to determine numeric characters:
Re. Search ("[0123456789]", charStr )! = None
[0123456789] is a regular expression in the form of a string. It is a character group and can be any character ranging from 0 to 9.
Net Regex. IsMatch (charStr, "[0123456789]");
By default, Search (Pattern, String) only determines whether a substring can match pattern. If pattern can match a part of String, it is considered that the match is successful, to test whether the entire String matches pattern, add ^ and $ at both ends of pattern. they indicate the start and end positions of the positioning String. This ensures that only the entire String can be matched by pattern.
For a character group like [0123456789], you can also use the range Notation: [0-9]
In a character group, "-" indicates the range. Generally, it is based on the corresponding code value of the character. The smaller the code value is before "-", and the larger one is behind.
In the above example, "-" is used to indicate the range and cannot match the X-ray character. This type of character is called metacharacters. For example, [,], ^, and $ are all metacharacters.
When we need to match these special metacharacters, we need to escape them.
Like the "-" character, if it is next to "[", it will be considered a common character. In other cases, it is a metacharacter. You can use "\" to escape the metacharacters:
Re. Search ("^ [0 \-9] $", "3 ")! = None // false
The above "\" character itself will be used together with other such characters as "\ n \ r". For separate use, "\" is also required for escape.
Use the native string: re. Search (r "^ [0 \-9] $", "3 ")! = None. Add r to the front of the string. "\" Is not used to represent.
Excluded character group: [^...]: indicates the current position, matching a character not listed.
[^ 0-9]: Indicates matching a character that is not a number.
Character group Notation:
Common examples include:
\ D: [0-9]
\ W: [0-9a-zA-Z] This also contains an underline
\ S: [\ t \ r \ n \ v \ f]
The following is a summary of excluded character groups:
\ D: complementary to \ d
\ W: complementary to \ w
\ S: complementary to \ s
The simplest application: [\ s \ S] is used in combination to match all characters.