This is a quick cheat sheet on some of the available parameters for regular expressions.
- How to handle alphanumeric characters and digits in a regular expression pattern?
Character | Description | Example pattern | Example match |
---|---|---|---|
\d | Digit | name_\d\d | name_11 |
\D | Non digit | \D\D\D | XYZ |
\w | Alphanumeric characters | \w-\w\w\w | B-a_2 |
\W | Non alphanumeric characters | \W\W\W\W\W | *-+=) |
\s | Contains a whitespace | x\sy\sz | x y z |
\S | Doesn’t contain a whitespace | \S\S\S\S | ATEST |
- How to handle occurrence in a regular expression pattern?
Character | Description | Example pattern | Example match |
---|---|---|---|
{2} | Occurs exactly 2 times | \D{2} | xy |
{2,3} | Occurs 2 to 3 times | \d{2,4} | 789 |
{4} | Occurs 4 or more times | \w{3,} | yyyxxxaaa |
* | Occurs zero or more times | X\*Y\*Z* | YYYZZ |
? | Occurs once or none | text? | text |
+ | Occurs one or more times | Chapter \w-\w+ | Chapter A-z2_2 |
I hope this was useful to you and let’s see what’s next?
Greetings,
Thomas
#regularexpression, #regex, #occurrence, #alphanumeric, #digit, #char, #characters, #cheatsheet
Leave a Reply