Regex Tester

Test and validate regular expressions in real time.

Regular Expressions: Complete guide for developers

Regular expressions (regex) are search patterns that allow you to find and extract specific text within larger strings. They are an incredibly powerful tool used in form validation, search and replace in text editors, log parsing, data extraction, and filtering. Every modern programming language supports regex through its standard library.

A regular expression is composed of literal characters (that match exactly) and special metacharacters (such as ., *, +, ?, [], (), {}, ^, $, |, \) that define patterns. Mastering regex allows you to solve text processing problems in one line that would otherwise require dozens of lines of code.

Practical use cases

Form validation: Verify emails, phone numbers, URLs, postal codes, and passwords before sending them to the server. Example email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/

Data extraction: Extract credit card numbers, dates, IPs, or any structured pattern from unformatted text like logs or emails.

Search and replace: In editors like VS Code, use regex to massively refactor code, such as converting all calls to an old function to a new format.

Available flags

  • g (Global): Finds all matches, not just the first one
  • i (Case insensitive): Ignores uppercase and lowercase
  • m (Multiline): ^ and $ match start/end of each line
  • s (Dotall): The dot (.) also matches line breaks
  • u (Unicode): Enables full support for Unicode characters

Frequently asked questions

What does each metacharacter mean?

. = any character, * = 0 or more times, + = 1 or more times, ? = 0 or 1 time, ^ = start of line, $ = end of line, [] = character class, () = capture group, | = alternation (OR), \ = escape.

What are capture groups?

Parentheses () create capture groups that allow you to extract specific parts of the match. For example, /(\d{2})\/(\d{2})\/(\d{4})/ captures day, month, and year separately. Named groups make subsequent referencing easier.

Can regex affect performance?

Yes, poorly designed regex can cause "catastrophic backtracking" with exponential complexity. Avoid nested quantifiers like (a+)+ and use tools like this one to test with large texts before using in production.

What's the difference between .* and .*?

.* is greedy: it matches as many characters as possible. .*? is lazy: it matches as few characters as possible. In practice, using lazy avoids problems when there are multiple matches on the same line.

Common regex patterns

PatternRegexExample
Email/^[^\s@]+@[^\s@]+\.[^\s@]+$/user@mail.com
URL/https?:\/\/[\w.-]+/https://example.com
Phone (US)/^\d{3}[-.]?\d{3}[-.]?\d{4}$/555-123-4567
IPv4/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/192.168.1.1