DEV Community

Vicky Vasilopoulou
Vicky Vasilopoulou

Posted on • Edited on

2 2

Regular Expressions CheatSheet!

Basics

Regular expressions always start with / /.

/ expression /, i.e /[A-Z]+/g basic format
/ name\?\*\\/ escape special characters with backslashes
() group with parentheses
| logical OR
Character classes
\w word \d digit \s whitespace (tabs, line breaks)
\W NOT word \D NOT digit \S NOT whitespace
\t tabs, \n line breaks
. any character
Enter fullscreen mode Exit fullscreen mode

Anchors

^world start of the strings
world$ end of the string
Enter fullscreen mode Exit fullscreen mode

Brackets

[xyz] match any x, y, z
[^xyz] NOT x, y, z
[B-X] match any capital letters between B & X.
Enter fullscreen mode Exit fullscreen mode

Quantification

viki|maria match viki or maria
z{n} n occurrences
z* zero or multiple occurrences
z+ one or multiple occurrences
z{min, max} min/max occurrences
z? zero or one occurrences
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay