Regex cookbook — Top 15 Most common regex

Jonny Fox
Factory Mind
Published in
4 min readMar 20, 2019

The most commonly used (and most wanted) regexes

UPDATE 10/2022: See further explanations/answers in story responses!

After some time I thought about publishing this article (see my previous tutorial) with the regex I used most in the projects on which I was involved.

Write in the comments any regex that you would like to add and I will try (if I can) to implement them 😅

Happy coding!!!

Alpha-numeric, literals, digits, lowercase, uppercase chars only

\w                //alpha-numeric only
[a-zA-Z] //literals only
\d
//digits only
[a-z]
//lowercase literal only
[A-Z]
//uppercase literal only

Simple numbers — try it!

Matches simple numbers only (no decimal nor fractions)

^(\d+)$.          15/12  8.5  12

Decimal numbers — try it!

^(\d*)[.,](\d+)$   15/12  8.5  12  8,7

Fractions — try it!

^(\d+)[\/](\d+)$   15/12  8.5  12

Alphanumeric without spaces — try it!

^(\w*)$            hello123
but not this text

Alphanumeric with spaces — try it!

^(\w*)$            hello123
this text
but not this!

Email (simple — see advanced section for more)

Classic email — try it!

^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})*$

jonny.fox@factorymind.com
hello@sdasdad.hello
but not this!

Email tokens — try it!

^([a-z0-9_\.\+-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$

Advanced Regex

Trim spaces — try it!

Matches text avoiding additional spaces

^[\s]*(.*?)[\s]*$

Jonny Fox
Factory Mind