Regular Expression (regex), Pattern AND Commonly Used Regular Expression

Web Developer Kaustubh
2 min readOct 25, 2020

--

Regular Expression In Programming

What Is Regular Expression ?

Regular expressions are patterns of characters that are used to perform pattern — matching.

It can be an object.The Patterns of character can be anything from a simple character , a fixed string or expression.Regular expressions help you find other strings or sets of strings using patterns.

What is use of Regular expressions ?

A] validation in programming language.

B]command line and text editor to find text form file.

C] it can save you thousands of hours if you work with text or need to parse large amounts of data.

How To Create Regular Expression ?

Commonly Use Regular Expressions

1]Regular expression for first name

[a-zA-Z]{2,}

2]Regular expressions for age

^(0?[1–9]|[1–9][0–9]|[1][0–9][0–9]|200)$

3]Regular expression for email

^\w+([-+.’]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$

4]Regular expression for PAN

[A-Z]{5}[0–9]{4}[A-Z]{1}

5]regular expression for Aadhar

^[2–9]{1}[0–9]{3}\\s[0–9]{4}\\s[0–9]{4}$

6]Regular expression for GST Number

^[0–9]{2}[A-Z]{5}[0–9]{4}[A-Z]{1}[1–9A-Z]{1}Z[0–9A-Z]{1}$

7]Regular expression for IFSC Code

^[A-Z]{4}0[A-Z0–9]{6}$

8]Regular expression for Mobile number validation

(0/91)?[7–9][0–9]{9}

9]Regular expression for only characters

/^[a-zA-Z]+$/

10]Regular expression for Whole number

/^\d+$/

11]Regular expression for decimal number

/^\d*\.\d+$/

12]Regular expression for alphabumberic charactors without space

/^[a-zA-Z0–9]*$/

13]Regular expression for alphabumberic charactors with space

/^[a-zA-Z0–9 ]*$/

14]Regular expression for HTTPS URL regular

/https?:\/\/(www\.)?[-a-zA-Z0–9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0–9@:%_\+.~#()?&//=]*)/

15]Regular expression for with or without HTTPS URL regular expression

/(https?:\/\/)?(www\.)?[-a-zA-Z0–9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0–9@:%_\+.~#?&//=]*)/

16]IP address validation (IPv4)

/(https?:\/\/)?(www\.)?[-a-zA-Z0–9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0–9@:%_\+.~#?&//=]*)/

17]Regular expression for IP address validation (IPv6)

/(([0–9a-fA-F]{1,4}:){7,7}[0–9a-fA-F]{1,4}|([0–9a-fA-F]{1,4}:){1,7}:|([0–9a-fA-F]{1,4}:){1,6}:[0–9a-fA-F]{1,4}|([0–9a-fA-F]{1,4}:){1,5}(:[0–9a-fA-F]{1,4}){1,2}|([0–9a-fA-F]{1,4}:){1,4}(:[0–9a-fA-F]{1,4}){1,3}|([0–9a-fA-F]{1,4}:){1,3}(:[0–9a-fA-F]{1,4}){1,4}|([0–9a-fA-F]{1,4}:){1,2}(:[0–9a-fA-F]{1,4}){1,5}|[0–9a-fA-F]{1,4}:((:[0–9a-fA-F]{1,4}){1,6})|:((:[0–9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0–9a-fA-F]{0,4}){0,4}%[0–9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0–5]|(2[0–4]|1{0,1}[0–9]){0,1}[0–9])\.){3,3}(25[0–5]|(2[0–4]|1{0,1}[0–9]){0,1}[0–9])|([0–9a-fA-F]{1,4}:){1,4}:((25[0–5]|(2[0–4]|1{0,1}[0–9]){0,1}[0–9])\.){3,3}(25[0–5]|(2[0–4]|1{0,1}[0–9]){0,1}[0–9]))/

18]Regular expression for IP address validation (IPV4 and IPv6)

/((^\s*((([0–9]|[1–9][0–9]|1[0–9]{2}|2[0–4][0–9]|25[0–5])\.){3}([0–9]|[1–9][0–9]|1[0–9]{2}|2[0–4][0–9]|25[0–5]))\s*$)|(^\s*((([0–9A-Fa-f]{1,4}:){7}([0–9A-Fa-f]{1,4}|:))|(([0–9A-Fa-f]{1,4}:){6}(:[0–9A-Fa-f]{1,4}|((25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)(\.(25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)){3})|:))|(([0–9A-Fa-f]{1,4}:){5}(((:[0–9A-Fa-f]{1,4}){1,2})|:((25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)(\.(25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)){3})|:))|(([0–9A-Fa-f]{1,4}:){4}(((:[0–9A-Fa-f]{1,4}){1,3})|((:[0–9A-Fa-f]{1,4})?:((25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)(\.(25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)){3}))|:))|(([0–9A-Fa-f]{1,4}:){3}(((:[0–9A-Fa-f]{1,4}){1,4})|((:[0–9A-Fa-f]{1,4}){0,2}:((25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)(\.(25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)){3}))|:))|(([0–9A-Fa-f]{1,4}:){2}(((:[0–9A-Fa-f]{1,4}){1,5})|((:[0–9A-Fa-f]{1,4}){0,3}:((25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)(\.(25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)){3}))|:))|(([0–9A-Fa-f]{1,4}:){1}(((:[0–9A-Fa-f]{1,4}){1,6})|((:[0–9A-Fa-f]{1,4}){0,4}:((25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)(\.(25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)){3}))|:))|(:(((:[0–9A-Fa-f]{1,4}){1,7})|((:[0–9A-Fa-f]{1,4}){0,5}:((25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)(\.(25[0–5]|2[0–4]\d|1\d\d|[1–9]?\d)){3}))|:)))(%.+)?\s*$))/

19]Regular expression for Regular Expression for Date Format YYYY-MM-dd

/([12]\d{3}-(0[1–9]|1[0–2])-(0[1–9]|[12]\d|3[01]))/

--

--

Web Developer Kaustubh

Sr.Web developer. love to code. PHP , Javascript, Mysql, Laravel, Jquey, git, project planing,Linux