Note This is a practical pattern covering the vast majority of real email addresses. The full RFC 5322 spec is far more complex and almost never needed. For production validation, prefer a library or send a confirmation email.
match emailvalidate emailemail regexextract email addressemail pattern
Note URL matching is inherently tricky due to the wide range of valid characters. This pattern handles most common HTTP/HTTPS URLs. For rigorous URL validation, use the URL constructor in JS or urllib.parse in Python.
match URLvalidate URLextract URLHTTP linkweb address pattern
JS: '192.168.1.1 and 999.999.999.999'.match(/\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/g)
Py: re.findall(r'\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b', text)
output
["192.168.1.1"] (999.999.999.999 rejected -- octets must be 0-255)
Note Each octet allows 0-255. The alternation order matters: check 25[0-5] before 2[0-4]\d before the general case. A simpler but less accurate version is \d{1,3}(\.\d{1,3}){3} which does not validate octet ranges.
IP addressvalidate IPIPv4 patternmatch IPnetwork address
Note Phone formats vary wildly by country. This covers common US formats: (555) 123-4567, 555-123-4567, 555.123.4567, +1 555 123 4567. For international numbers, consider a library like libphonenumber.
phone numbervalidate phonematch phonetelephone regexUS phone format
JS: '2026-04-04 and 12/25/2025'.match(/\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])/g)
Py: re.findall(r'(?:0[1-9]|1[0-2])/(?:0[1-9]|[12]\d|3[01])/\d{4}', text)
output
JS: ["2026-04-04"]
Py: ["12/25/2025"]
Note Regex validates format but not logical correctness -- it will accept 02/31/2026 (Feb 31 does not exist). For actual date validation, parse the match with Date (JS) or datetime (Python) afterward.
date formatvalidate datematch dateYYYY-MM-DDparse datedate regex
Note Rules: must start with a letter, 3-20 characters total, allows letters, digits, dots, underscores, and hyphens. Adjust the {2,19} range for your app's requirements (first char + 2-19 more = 3-20 total).
Note Matches both 3-digit (#RGB) and 6-digit (#RRGGBB) hex colors. The {1,2} quantifier on the 3-char group handles both lengths. Does not cover 8-digit RGBA hex -- extend to {1,2,} won't work; add a separate alternation for #RRGGBBAA if needed.
hex colorcolor codevalidate hexCSS colormatch color
Note Captures only the last extension. For double extensions like .tar.gz, match /\.tar\.gz$/ explicitly or extract both with /\.([a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*)$/. Alternatively, use path.extname (Node) or os.path.splitext (Python).
Full: "<div class=\"box\">content</div>"
Group 1: "div", Group 2: "content"
Note This works for simple, non-nested cases only. Regex CANNOT reliably parse nested HTML -- nested tags, self-closing tags, comments, and CDATA sections break pattern-based approaches. Use a proper HTML parser (DOMParser, BeautifulSoup, cheerio) for production code.
HTML tagmatch tagextract HTMLparse HTMLtag content
Whitespace Trimming
syntax
/^\s+|\s+$/g
example
JS: ' hello world '.replace(/^\s+|\s+$/g, '')
Py: re.sub(r'^\s+|\s+$', '', ' hello world ')
output
"hello world"
Note Equivalent to str.trim() in JS and str.strip() in Python. The regex version is useful when you also want to normalize internal whitespace: replace /\s+/g with ' ' after trimming.
trim whitespacestrip spacesremove leading trailingclean whitespace
Note Validates US-formatted numbers with optional commas every 3 digits and optional decimal part. European formats swap comma and period -- adjust the pattern accordingly. The leading -? handles negative numbers.
number formatcomma separated numbervalidate numberdecimal numberformatted number