Menu

Regex Tester

Test and validate regular expressions with real-time matching and detailed results.

Results

No matches found.

About Regular Expressions

What is a Regular Expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. It's a powerful tool for matching, searching, and manipulating text based on patterns.

Regular expressions are used in programming languages, text editors, and other tools to:

  • Validate input formats (emails, phone numbers, etc.)
  • Extract specific data from text
  • Replace text based on patterns
  • Split strings into components
  • Find and extract information from large text datasets

Regular expressions are supported in most programming languages, including JavaScript, Python, Java, and many others, making them a universal tool for text processing.

Regular Expression Cheat Sheet

Basic Patterns

PatternDescription
.Any single character (except newline)
\wWord character (letter, digit, underscore)
\dDigit (0-9)
\sWhitespace character
^Start of string (or line with m flag)
$End of string (or line with m flag)

Quantifiers

PatternDescription
*Zero or more occurrences
+One or more occurrences
?Zero or one occurrence
{n}Exactly n occurrences
{n,}n or more occurrences
{n,m}Between n and m occurrences

Character Classes

PatternDescription
[abc]Any character in the set
[^abc]Any character not in the set
[a-z]Any character in the range
[0-9]Any digit (same as \d)

Groups & Flags

PatternDescription
(abc)Capturing group
(?:abc)Non-capturing group
(?abc)Named capturing group
gGlobal flag (find all matches)
iCase-insensitive flag
mMultiline flag (^ and $ match line boundaries)

Common Examples

/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/

Email validation

/^\d{3}-\d{2}-\d{4}$/

Social Security Number

/^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/

URL matching

/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/

IPv4 address

/^(0?[1-9]|1[0-2]):[0-5][0-9]$/

Time Format HH:MM 12-hour, optional leading 0

/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/

Time Format HH:MM 24-hour, optional leading 0

/(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)/

Time Format HH:MM:SS 24-hour

/^[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}$/

Date Format dd/mm/yyyy

/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/

Moderate Password (8+ chars, 1 uppercase, 1 lowercase, 1 number)

/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{8,}$/

Complex Password (8+ chars, 1 uppercase, 1 lowercase, 1 number, 1 special)

/^\d{5}(-\d{4})?$/

US ZIP Codes (5 digits with optional 4-digit extension)

/^4\d{12}(\d{3})?$/

Visa Credit Card Numbers (13 or 16 digits starting with 4)

Common Use Cases

Data Validation

  • Email address format verification
  • Phone number format validation
  • Password strength requirements
  • Credit card number validation

Data Extraction

  • Extract URLs from text
  • Find hashtags in social media content
  • Extract dates from documents
  • Parse log files for specific events

Text Processing

  • Find and replace text patterns
  • Format text according to patterns
  • Split text into components
  • Clean and normalize text data

Web Development

  • URL routing and parameter extraction
  • Form validation on the client side
  • Sanitize user input for security
  • Extract data from HTML/XML