Cheat sheet on some of the available parameters for regular expressions

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?
CharacterDescriptionExample patternExample match
\dDigitname_\d\dname_11
\DNon digit\D\D\DXYZ
\wAlphanumeric characters\w-\w\w\wB-a_2
\WNon alphanumeric characters\W\W\W\W\W*-+=)
\sContains a whitespacex\sy\szx y z
\SDoesn’t contain a whitespace\S\S\S\SATEST
  • How to handle occurrence in a regular expression pattern?
CharacterDescriptionExample patternExample 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 timesX\*Y\*Z*YYYZZ
?Occurs once or nonetext?text
+Occurs one or more timesChapter \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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: