Collect some Regex 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
index of the first match between the regular expression and the given string;
if not found, -1.
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
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
Matches a non-word boundary.
digit character. Equivalent to [0-9].
Matches a non-digit character. Equivalent to [^0-9].
Matches a carriage
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_].