Regex cookbook — Top 10 Most wanted regex

The most commonly used (and most wanted) regexes

UPDATED 5/15/19! 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!!!

Trim spaces — try it!

Matches text avoiding additional spaces


HTML Tag — try it!

Matches any valid HTML tag and the corresponding closing tag


Hexadecimal value — try it!

Matches any valid hex color inside text


Valid email (RFC5322) — try it!

Matches any valid email inside text


Username (simple) — try it!

Minimum length of 3, maximum length of 16, composed by letters, numbers or dashes.


Strong password — try it!

Minimum length of 6, at least one uppercase letter, at least one lowercase letter, at least one number, at least one special character


URL (http, https or ftp) — try it!

If you want to use capturing groups to get scheme, path, etc. (or add user-info, host, port…) feel free to ask it in comments!


IPv4 address — try it!

Matches any valid IPv4 address inside text


“Defanged” URL or IPv4 address — try it!


SSN — Social Security Number (simple) — try it!

If you want to check the validity of an SSN feel free to ask in comments!


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

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

Have fun and do not forget to recommend the article if you liked it 💚

Do not forget to check out my previous article about regex tutorial!