Regular Expression (regex or regexp)

Domain Name regular expression

^[a-z0-9]+[a-z0-9-\.]*[a-z0-9]+\.[a-z\.]{2,5}$

IP-address regular expression
This will match any IP-address between 0.0.0.0 to 255.255.255.255

^(([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])$

Decimal value regular expression
Following pattern will match any decimal digit of any size.

^[0-9]+$

URL regular expression

^http[s]?://[a-z0-9-\.]+\.[a-z\.]{2,5}(/[a-z0-9%\-_\.\?=&@#]*)?$

Float value regular expression
This will match any floating point value eg 1.2 , 2.009 or .987 but not match 1.00 or 239

^[0-9]*\.[0-9]*[1-9]+$

Hexadecimal color regular expression
This Regex pattern will match any 3 or 6 digit hexadecimal value eg: FF2 or 33CCEE

^([a-f0-9]{6}|[a-f0-9]{3})$

username  regular expression
Following pattern will match alphanumeric string including “_” of length 3 to 16.

^[a-z0-9_]{3,16}$

email regular expression

^[a-z0-9]+[_a-z0-9\.-]*[a-z0-9]+@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$

Leave a Reply

Your email address will not be published. Required fields are marked *