Collect some RegExp concepts and demos from MDN.
(Some of these demos modified by myself).
Returns true or false
If the regex has the global flag set, test() will advance the lastIndex of the regex.
The exec() method executes a search for a match in a specified string. Returns a result array, or null.
once use ‘\g’
and the re has lastIndex property
The index of the first match between the regular expression and the given string;
if not found, -1.
An Array containing the entire match result and any parentheses-captured matched results;
null if there were no matches.
once use ‘\g’
Switching words in a string
matches any single character except the newline character.
not match na
Matches ‘x’ and remembers the match, as the following example shows. The parentheses are called capturing parentheses.
Matches ‘x’ but does not remember the match.
And let you define subexpressions for regular expression operators to work with.
Matches ‘x’ only if ‘x’ is not followed by ‘y’
This pattern type matches any one of the characters in the brackets, including escape sequences.
It matches anything that is not enclosed in the brackets
Matches a word boundary.
Matches a non-word boundary.
Matches a digit character. Equivalent to [0-9].
Matches a non-digit character. Equivalent to [^0-9].
Matches a carriage return
Matches a single white space character, including space, tab, form feed, line feed.
Matches any alphanumeric character including the underscore. Equivalent to [A-Za-z0-9_]
Matches any non-word character. Equivalent to [^A-Za-z0-9_].