CoderTools

Regex Tester

Test and debug regular expressions with instant match results

Match Results

No matches found

                    

Match Details

Enter a regex pattern and test text to see detailed match information
/ /

Quick Templates

Replace Function

Use $1, $2, etc. for captured groups

                        
sed 's/pattern/replacement/g' input.txt
This sed command can be used in Unix/Linux/macOS terminal or Git Bash on Windows

Regular Expression Testing Tool Documentation

Regular Expression Flags

g
Global
Find all matches, not just the first one
i
Ignore Case
Case-insensitive matching
m
Multiline
^ and $ match line boundaries

Common Regular Expression Patterns - Quick Reference

Character Classes

\\d Any digit (0-9)
Equivalent to [0-9]
\\D Any non-digit character
\\w Word character (a-z, A-Z, 0-9, _)
Equivalent to [a-zA-Z0-9_]
\\W Any non-word character
\\s Whitespace (space, tab, newline)
Includes space, \t, \n, \r, \f, \v
\\S Any non-whitespace character
. Any character except newline
[abc] Any character in the set
[^abc] Any character NOT in the set

Quantifiers

* 0 or more (greedy)
Greedy: matches as much as possible
+ 1 or more (greedy)
? 0 or 1 (optional)
{n} Exactly n times
{n,} n or more times
{n,m} Between n and m times
*? Lazy quantifier
Add ? after quantifier to make it non-greedy

Anchors & Boundaries

^ Start of line/string
$ End of line/string
\\b Word boundary
Between \w and \W
\\B Non-word boundary

Groups & Lookarounds (Advanced)

(abc) Capturing group
Captures matched text for backreferences ($1, $2...)
(?:abc) Non-capturing group
Groups without capturing (better performance)
(?=abc) Positive lookahead
Example: \d(?=px) matches digits followed by 'px'
(?!abc) Negative lookahead
(?<=abc) Positive lookbehind
(?<!abc) Negative lookbehind

Special Characters (Must Be Escaped)

Escape with backslash (\) to match literally: . * + ? ^ $ { } [ ] ( ) | \
Example: \. matches a literal dot, \* matches a literal asterisk

Practical Examples

Email Address Validation

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

Matches: one or more valid characters, followed by @, domain name, and 2+ letter extension.

Matches user@domain.com, test.email+tag@example.org

Phone Number (US Format)

\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})

Captures area code, exchange, and number with flexible formatting.

Matches (555) 123-4567, 555.123.4567, 555-123-4567

URL Matching

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

Matches HTTP/HTTPS URLs with optional www prefix and various path formats.

Matches https://example.com, http://www.site.org/path

Strong Password Validation

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

Requires at least 8 characters with lowercase, uppercase, and digit.

Matches Password123, MyStr0ngP@ss

Advanced Features

Capturing Groups
Use parentheses () to capture parts of matches for replacement
([0-9]{4})-([0-9]{2})-([0-9]{2})
Lookahead/Lookbehind
Match based on what comes before/after without including it
(?=.*password)
Non-capturing Groups
Group without capturing using (?:pattern)
(?:http|https)://

Tips and Best Practices

  • Start simple and build complexity gradually
  • Use the global flag (g) to find all matches
  • Escape special characters with backslash (\)
  • Test thoroughly with various input examples
  • Use capturing groups for complex replacements
  • Consider performance with large texts

sed Command Generation

This tool automatically generates equivalent sed commands based on your regex pattern and replacement text, making it easy to use regex in Unix/Linux command line.

Search Mode (Empty Replacement)

When replacement text is empty, generates a search command to print matching lines only.

sed -n '/pattern/p' input.txt
Example: Pattern: error
Result: Prints all lines containing 'error'

Replace Mode (With Replacement)

When replacement text is provided, generates a substitution command.

sed 's/pattern/replacement/flags' input.txt
Example: Pattern: foo, Replace: bar
Result: Replaces all 'foo' with 'bar'
Note: Special characters are automatically escaped. The generated command works in Unix/Linux/macOS terminals and Git Bash on Windows.

Quick Menu

No recent tools