This tutorial will show you some of the most common regular expressions you can use in your web applications.
What Are Regular Expressions?
Regular Expressions, or
regex for short, are patterns defined to compare against user input or other text strings. They're beneficial in cases where you need to validate some type of user input, including email addresses, phone numbers, ZIP codes, and more.
Most Common Regular Expressions
Here is a quick list of some of the most common regular expressions you can use throughout your web applications:
This regex will match against any valid email address:
This regex will match against any valid URL, allowing for both "http" and "https" protocols, and optional "www.":
This regex will match against a 7- or 10-digit phone number:
This regex will match against a 5-digit ZIP code, or a 9-digit ZIP code containing both the main ZIP code and optional ZIP+4 with a hyphen:
That's the rundown of the most common regular expressions. If you have any you would like to see added that would help others, let me know in the comments below.
Created: July 20, 2022