Regular Expressions Cheatsheet
Regular expression - a sequence of characters representing a pattern.
They are pretty hard to maintain:
If you’ll use regular expression to solve a problem, you’ll have two problems.
Regular expressions are case-sensitive by default.
We need to keep in mind the special characters, like
It’s generally better to re-use the regular expressions available over the Internet, as they are pretty tricky to write and maintain. The bugs in these are probably fixed by the community already.
|match only the pattern that occures at the beginning of the line|
|match only the pattern that occures at the end of the line|
|word (a-z, A-Z, 0-9, |
|not word (plus |
|number of 2 digits|
|Polish zip code (12-345)|
|at least one occurence|
|at least one digit|
|0 or more occurences|
|exactly 3 occurences|
|exactly 3 digits|
|between 1 and 3 occurences|
|set of matched characters or range|
|either space or |
|letter between A-Z|
|space OR |
|dot (escaped |
|match all occurences|
|make the expression case-insensitive|
|encapsulate expression in a group|
# Groups indexing
Groups are indexed from 1.
$2 - first group in matched pattern
# Phone number
There’s no perfect email regex, but this one is pretty close.
- rgb(1, 2, 3);
- rgba(1, 2, 3, 0.4);
# Ideas to explore
Regular Expressions aren’t usable only for programming. They can be used to:
- Automating the e-mails management via Zapier/Make.com
- labeling the e-mails
- sending them to Todoist