Regex: regular expression cheat sheet
Publisher: Psychz Networks, August 23,2018"REGEX" abbreviation for Regular expressions are highly useful in extracting information from any text by using a particular search pattern (ASCII or Unicode characters) for one or more matches.
Regex is used in many applications ranging from web scraping, translating data to other formats, validation to parsing/replacing strings.
This tool is compatible with almost all the programming languages including JavaScript, Java, VB, C #, C / C++, Python, and many others).
Anchors — ^ and $
^ |
This symbol indicates start of a string |
$ |
This symbol indicates end of a string |
Quantifiers — * + ? and {}
The symbols '*', '+', and '?', denote the number of times a character or a sequence of characters may occur. What they mean is: "zero or more", "one or more", and "zero or one."
You can also use bounds, which appear inside braces {} and indicate ranges in the number of occurrences:
* |
Matches 0 or more of the previous character (e.g. ab*c will generate output as “ac”, “abc”, “abbc”, etc. |
? |
Matches 0 or 1 of the previous character |
+ |
Matches 1 or more of the previous character |
{x} |
Matches exactly x number of times |
{x, y} |
Matches everything between x, y characters |
OR operator — | or []
| |
Matches a character or group of characters on either side (e.g. a|b corresponds to a or b) |
[] |
This works exactly as previous |
Character classes — \d \w \s and .
\d |
Matches one digit |
\D |
Performs inverse matches of \d |
\w |
Matches a word character |
\W |
Performs inverse matches of \w |
\s |
Matches a whitespace character |
\S |
Performs inverse matches of \s |
. |
Matches any character*. Hence called a Wildcard ; *except newline (/n). |