Regular expressions are a type of value that can match with strings.
The examples below use the match method. Visit methods.html to see other methods which can utilize regular expressions.
A regular expression or regex is bracketed by backslashes.
The regex below can match with strings containing "abc".
You can also create a regex with the RegExp constructor.
The RegExp constructor lets you make regexes out of variables.
Special characters will still be interpreted as special characters.
Escape the special characters.
Certains characters, called tokens, have special meaning in regexes. For example, a period will match any single character.
\d matches digits.
\D matches nondigits.
\w will match digits, alphabetic charcers, and underscores.
\W matches all other characters.
\s matches whitespace characters such as spaces, tabs, and line feeds.
\S matches nonwhitespace characters.
A "+" will match one or more of the preceding character.
A "?" modifier will match zero or one of the preceding character.
And a "*" will match zero or more of the preceding character.
Use curly braces to match a character only 'n' times.
Use curly braces to match a character at least 'n' times.
Use curly braces to match a character 'n' times, but not more than 'm' times.
Square brackets let you define your own group of characters.
Backreferences allow you to utilize matches.
Please visit methods.html to see methods which can utilize regular expressions.