c regular guidelines groups of characters

  • 2020-05-07 20:18:48
  • OfStack

Character group: any of various characters that may appear in the same place.

Use regular expressions to determine numeric characters:

re.Search("[0123456789]",charStr) != None

Where [0123456789] gives the regular expression in the form of a string, which is a 1 character group, indicating that it can be any 1 character from 0 to 9.
In Net Regex. IsMatch (charStr, "[0123456789]");
By default, Search (Pattern String) will determine whether a particular substring matching pattern, as long as pattern can match String in part 1, is considered to be a match, in order to test whether the whole String can match pattern, ends in pattern plus ^ and $. They said the beginning and end of a string, so it can guarantee, only is the entire String can by pattern matching, in order to be successful.
Like the [0123456789] character group, you can also use range notation: [0-9]

In the character group: "-" represents the range, 1 generally according to the character corresponding to 1 code value, code value in the small "-" in front of, large in the back.
In the above example, the "-" is used to indicate the range and does not match the horizontal character. These 1 characters are called metacharacters, such as [,], ^, and $are metacharacters.

So when we need to match these special metacharacters, we need to escape.
Like "-" character, if it is next to "[", will be considered as a normal character, other cases are metacharacters, you can use" \ ", metacharacters escape:
re.Search("^[0\\-9]$","3") != None //false
The "\" character itself is used in conjunction with other characters such as "\n \r", etc.
Use native strings: re.Search (r"^[0\-9]$","3")! = None, prefix the string with r. So instead of saying "\" you can say "\".
Exclude type character group: [^...] : represents the current position, matching 1 unlisted character.
[^0-9] : matches a character that is not a number
Character group shorthand:
Common examples are:
\ d: [0-9]
\w: [0-9a-zA-Z] this also includes an underscore
[\ t \ r \ \ s: n \ v \ f]

The corresponding exclusions character group shorthand:
\D: supplementary to \d
\W: supplementary to \w
\S: supplementary to \s
Simplest application: [\s\S] combined to match all characters.

Related articles: