Back to Dev Tools

RegEx Tester & Validator

Test regular expressions with live validation and match highlighting. Perfect for debugging patterns and learning regex.

๐Ÿ”ค Regular Expression

Common Flags:

๐Ÿ“ Test String

Characters: 0

๐ŸŽฏ Results (0 matches)

Enter pattern and test string

Results will appear here

Quick Reference

Basic Patterns

. - Any character
\\d - Any digit
\\w - Word character
\\s - Whitespace

Quantifiers

+ - One or more
* - Zero or more
? - Zero or one
{n,m} - Between n and m

Anchors

^ - Start of string
$ - End of string
\\b - Word boundary
\\B - Non-word boundary

Complete Regular Expressions Guide

๐Ÿ“š What Are Regular Expressions?

Regular expressions (regex) are powerful pattern-matching tools used to search, validate, and manipulate text. They provide a concise way to describe complex text patterns using special characters and syntax rules.

Why Learn Regex?

  • โ€ข Data Validation: Email, phone, password validation
  • โ€ข Text Processing: Search and replace operations
  • โ€ข Log Analysis: Extract specific information from logs
  • โ€ข Web Scraping: Parse HTML and extract data
  • โ€ข Code Analysis: Find patterns in source code

Real-World Applications

Used in programming languages (JavaScript, Python, Java), text editors (VS Code, Sublime), command-line tools (grep, sed), databases (MySQL, PostgreSQL), and web development frameworks.

๐ŸŽฏ How to Use This Tester

1

Write Your Pattern

Enter your regex pattern in the Pattern field. Start simple with literal text, then add special characters for complex matching.

2

Set Flags

Use flags to modify behavior: 'g' for global matching, 'i' for case-insensitive, 'm' for multiline mode.

3

Test Against Text

Enter sample text to see matches highlighted in real-time. View detailed results including match positions and capture groups.

4

Debug and Refine

Iterate on your pattern, test edge cases, and use our reference guide to learn new syntax elements.

Complete Regex Syntax Reference

๐Ÿ“ Character Classes

.Any character except newline
\\dAny digit [0-9]
\\DAny non-digit
\\wWord char [a-zA-Z0-9_]
\\WNon-word character
\\sWhitespace [ \\t\\n\\r]
\\SNon-whitespace

๐Ÿ”ข Quantifiers

*Zero or more
+One or more
?Zero or one (optional)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?Non-greedy (lazy)

โš“ Anchors & Boundaries

^Start of string/line
$End of string/line
\\bWord boundary
\\BNon-word boundary
\\AStart of string only
\\ZEnd of string only

๐Ÿ”— Groups & Alternatives

(abc)Capturing group
(?:abc)Non-capturing group
a|bAlternation (or)
\\1Backreference
(?=abc)Positive lookahead
(?!abc)Negative lookahead

๐ŸŽจ Character Sets

[abc]Any of a, b, or c
[^abc]Not a, b, or c
[a-z]Lowercase letters
[A-Z]Uppercase letters
[0-9]Digits
[a-zA-Z0-9]Alphanumeric

๐Ÿšฉ Flags & Modifiers

gGlobal (all matches)
iCase insensitive
mMultiline mode
sDot matches newline
uUnicode mode
ySticky mode

Common Patterns and Real-World Examples

๐Ÿ“ง Validation Patterns

Email Address

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

Validates basic email format with username, @ symbol, domain, and TLD.

Phone Number (US)

^(\\+1[- ]?)?\\(?([0-9]{3})\\)?[- ]?([0-9]{3})[- ]?([0-9]{4})$

Matches various US phone number formats: (555) 123-4567, 555-123-4567, +1 555 123 4567.

Strong Password

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

Requires 8+ characters with lowercase, uppercase, digit, and special character.

๐Ÿ” Text Processing Patterns

Extract URLs

https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)

Finds HTTP and HTTPS URLs in text content.

Credit Card Numbers

^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})$

Matches Visa, MasterCard, and American Express card formats.

IP Address (IPv4)

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

Validates IPv4 addresses with proper range checking (0-255 per octet).

Regex Best Practices and Performance Tips

โœ… Best Practices

๐ŸŽฏ Be Specific

Use precise patterns rather than overly broad ones:

โŒ Bad: .+ (matches everything)
โœ… Good: [A-Za-z0-9]+ (specific characters)

โš“ Use Anchors

Anchor patterns to prevent unintended matches:

โŒ Bad: \\d{3} (matches 123 in 123456)
โœ… Good: ^\\d{3}$ (exactly 3 digits)

๐Ÿ“ Use Comments and Naming

Document complex patterns and use named groups for clarity. Consider breaking very complex patterns into multiple simpler ones.

๐Ÿšซ Common Pitfalls

๐Ÿ’ฅ Catastrophic Backtracking

Avoid nested quantifiers that can cause exponential time complexity:

โŒ Dangerous: (a+)+b
โœ… Better: a+b

๐Ÿ”„ Greedy vs Non-Greedy

Understand the difference between greedy and lazy quantifiers:

Greedy: <.+> (matches <a>text</a>)
Lazy: <.+?> (matches <a> only)

๐Ÿงช Always Test Edge Cases

Test with empty strings, very long inputs, special characters, and malformed data. What works for normal input might fail catastrophically on edge cases.

Frequently Asked Questions

Q: What's the difference between .* and .+?

A: .* matches zero or more of any character (including empty string), while .+ matches one or more (requires at least one character). Use .+ when you need to ensure something exists, .* when optional.

Q: Why isn't my regex matching across multiple lines?

A: By default, . doesn't match newline characters, and ^ and $ only match string start/end. Use the 'm' flag for multiline mode (^ and $ match line boundaries) and 's' flag for dotall mode (. matches newlines).

Q: How do I match a literal special character?

A: Escape special characters with backslashes: \. \+ \* \? \[ \] \( \) \ \^ \$ \| \\. Inside character classes [like this], most characters don't need escaping except ] ^ - and \.

Q: What are capture groups and how do I use them?

A: Capture groups (parentheses) save matched portions for later use. In "Hello (\\w+)", the word after "Hello " is captured as group 1. Use \\1, \\2, etc. to reference captured groups within the same pattern, or access them programmatically in your code.

Q: When should I use regex vs string methods?

A: Use regex for pattern matching, validation, and complex text processing. Use simple string methods (contains, startsWith, etc.) for literal text searches - they're faster and more readable. If you can solve it simply without regex, do so.

Q: How can I make my regex more readable?

A: Break complex patterns into smaller parts, use non-capturing groups (?:...) to organize without creating unnecessary captures, add comments in your code explaining what each part does, and consider using multiple simpler regexes instead of one complex one.

Q: Why is my regex slow on large text?

A: Common causes include catastrophic backtracking from nested quantifiers, overly broad patterns that force excessive backtracking, or missing anchors. Use atomic groups, possessive quantifiers, or break up the text into smaller chunks for processing.

Q: Are regex engines different across programming languages?

A: Yes, while basic syntax is similar, there are differences in supported features, performance, and behavior. JavaScript, Python, Java, and .NET all have slightly different regex implementations. Our tester uses JavaScript's regex engine, so results match browser/Node.js behavior.