Overview
A regular expression is a set of rules that are declared in advance to match characters in a string.
Basic syntax
Metacharacters
In the pattern of regular expressions, there are some characters that have special meaning and are called meta characters. Metacharacters are matched for a single character.
\w match uppercase and lowercase characters and numbers 0 to 9 of any and underscore, equivalent to [a-za-z0-9_]
\w does not match the size of the English character and the number 0 to 9 of any one, equivalent to [^a-za-z0-9_]
\s matches any whitespace character, equivalent to [\f\n\r\t\v]
\s matches any non-white-space character, equivalent to [^\s]
\d matches any single number from 0 to 9, equivalent to [0-9]
\d does not match any single number from 0 to 9, equivalent to [^0-9]
[\U4E00-\U9FA5] matches any single Chinese character (Unicode encoding is used here to denote Chinese characters)
Defining character
The more common regular expression qualifier is the double slash/regex/
The concept of atoms
The atoms in the regular expression are divided into visible atoms and invisible atoms.
[\f\n\r\t\v] belongs to invisible atoms, others represent visible atoms
Quantifiers
\* matches 0 to multiple metacharacters, equal to {0,}
? Matches 0 to 1 metacharacters, equivalent to {0,1}
{n} matches n-ary characters
{N,} matches at least n metacharacters
{N,m} matches n to M metacharacters
\+ matches at least 1 metacharacters, equal to {1,}
Boundary
\b Match word boundaries
^ string must start with the specified character
The $ string must end with the specified character
Capturing groupings
In regular expressions, use () to organize several units (which can be characters, regular expressions) together to become a self-contained unit.
In regular expressions, groupings are grouped into capture groupings and non-capture groupings.
Mode correction
Greedy/lazy, ignoring case, ignoring whitespace characters
Working with scenes
form validation, template engine
The above mentioned is the entire content of this article, I hope you can enjoy.