js正则表达式语法大全(JS regular expression syntax Daquan)
js正则表达式语法大全(JS regular expression syntax Daquan)
regular expression syntax
A regular expression is a text pattern consisting of regular characters (such as characters a to Z) and special characters (called meta characters). This pattern describes one or more strings to match when searching for a text body. A regular expression, as a template, matches a character pattern with the string it searches for.
Here are some examples of regular expressions that might be encountered:
JScript VBScript matching
/^\[\t]*$/ "^\[\t]*$, a blank line.
/\d{2}-\d{5}/ "\d{2}-\d{5}" verifies whether a ID number is made up of a 2 digit number, a hyphen, and a 5 digit number.
/ (. *) ">.*/" (. *) >.*, a HTML marker.
The following table is a complete list of meta characters and their behavior in the context of regular expressions:
Character description
Mark the next character as a special character, or a literal character, or a backward reference, or an octal escape character. For example, the'n'matches the character "n"". '\n'matches a newline character. Sequence matching "\" and \ \ '\ ("," (".
Matches the start position of the input string. If you set the Multiline attribute of the RegExp object, ^ matches the position after'\n'or'\r'.
$matches the end position of the input string. If the Multiline property of the RegExp object is set, $matches the location before'\n'or'\r'.
* matches the previous sub expression zero or more times. For example, zo* can match "Z" and "zoo"". * equivalent to {0}.
+ matches the previous sub expression one or more times. For example,'zo+'matches "Zo" and "zoo", but does not match "Z"". + is equivalent to {1}.
Matches the previous sub expression zero or twice. For example, "do (ES)" can match the "do" in "do" or "does"". Equivalent to {0,1}?.
{n} n is a nonnegative integer. Match the specified n times. For example,'o{2}'does not match the'o' in Bob, but it matches the two o in food.
{n,} n is a nonnegative integer. Match at least n times. For exa