CoderTools

Regex Tester

Test and debug regular expressions with instant match results

Match Results

No matches found

                    

Match Details

/ /

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

What is Regular Expression?

Regular expressions (regex) are powerful pattern-matching tools used in programming to search, extract, and manipulate text. They use special characters and syntax to define search patterns that can match strings of characters.

Regular expressions are widely used for data validation, text processing, log analysis, and search-and-replace operations. They provide a concise and flexible way to identify patterns in text.

How to Use This Tool

  1. Choose a quick template or enter your regular expression pattern
  2. Set appropriate flags (g for global, i for ignore case, m for multiline)
  3. Input or load sample test text
  4. View real-time match results and detailed information
  5. Use the replace function to test substitutions

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

Basic Patterns
\\d - Any digit (0-9)
\\w - Word character (a-z, A-Z, 0-9, _)
\\s - Whitespace character
. - Any character except newline
Quantifiers
+ - One or more
* - Zero or more
? - Zero or one
{n} - Exactly n times
Anchors
^ - Start of line
$ - End of line
\\b - Word boundary

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.

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.