Common Regular Expressions Handbook

rahul nayak

A regular expression is a sequence of characters used for parsing and manipulating strings.

Regular expressions are such an incredibly convenient tool, available across so many languages that most developers will learn them sooner or later. Fields of application of regular expressions ranges from validation to parsing/replacing strings, capturing specific strings and web scraping.

Background Info on Regular Expressions

This is what Wikipedia has to say about them:

In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. Regular expressions (abbreviated as regex or regexp, with plural forms regexes, regexps, or regexen) are written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.

In this article, we will go over some most common regular expressions which coders use to perform their tasks often. Before that we will understand what some symbols mean in regular expressions.

Regular Expressions Cheat Sheet

Common Regular Expressions


  • Whole Numbers — ^\d+$
  • Decimal Numbers — ^\d*\.\d+$
  • Whole + Decimal Numbers — ^\d*(\.\d+)?$
  • Negative, Positive Whole + Decimal Numbers — ^-?\d*(\.\d+)?$
  • Whole + Decimal + Fractions — [-]?[0-9]+(\.)?[0-9]*([\/][0-9]+[,.]?[0-9]*)*

Alphanumeric Characters




Password Strength

A strong password should have 1 lowercase letter, 1 uppercase letter, 1 number, 1 special character and be at least 8 characters long.




IP Address(Only IPv4)



The elements are separated by ‘/’ or ‘ -’ or ‘.’. And also there is check for leap year.



  • Time Format HH:MM 12-hour, optional leading 0
  • Time Format HH:MM 12-hour, optional leading 0, Meridiems (AM/PM)
    ((1[0-2]|0?[1-9]):([0-5][0-9]) ?([AaPp][Mm]))
  • Time Format HH:MM 24-hour with leading 0
  • Time Format HH:MM 24-hour, optional leading 0

Date and Time in ISO-8601 Format


Phone Numbers

^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(\d+))?$



Hex Color Codes




US Zip Codes


India Zip Codes


Morse Codes

Using . for a dot, for a dash, separating letters by spaces and words by|.

^[.-]{1,5}(?:[ \t|]+[.-]{1,5})*(?:[ \t|]+[.-]{1,5}(?:[ \t|]+[.-]{1,5})*)*$

File Paths

(\/)?[a-z0-9 _@\-^!#$%&+={}.\/\\\[\]]+(\.[a-z]+)?$


In this blog, we learnt about common regular expressions. This article can be used as a reference for handbook for regular expressions. Regular expressions are used by developers most often. So, I think it will be helpful. In case I encounter more regular expressions, I will add them here.

    rahul nayak

    Written by

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade