Skip to main content
The RegExp Tester tool provides an interactive environment for testing regular expressions against sample text. It supports all JavaScript regex flags, displays match positions, and extracts capture groups for detailed pattern analysis.

Features

  • Full JavaScript regex syntax support
  • All standard flags (g, i, m, s, u, y)
  • Match highlighting with positions
  • Capture group extraction
  • Match count and indexing
  • Real-time error reporting

Use Cases

Pattern Development

Test and refine regex patterns before using them in production code

Data Validation

Validate input patterns like emails, phone numbers, and URLs

Text Extraction

Extract specific data patterns from unstructured text

Log Parsing

Build patterns to parse and extract information from log files

Regex Flags

Select flags by changing the action:
FlagNameDescription
gGlobalFind all matches (not just first)
iIgnore CaseCase-insensitive matching
mMultiline^ and $ match line boundaries
sDotAll. matches newlines
uUnicodeEnable full Unicode support
yStickyMatch from lastIndex position

Common Flag Combinations

  • Default: gm (global, multiline)
  • Case-insensitive search: gi
  • Single match: i (no global flag)
  • Unicode text: gu

Input Format

Pattern (Main Input)

Enter the regular expression pattern without delimiters:
\d{3}-\d{3}-\d{4}
Do not include / delimiters. Enter only the pattern. Flags are set via the action parameter.

Test String (Second Input)

The text to test against:
Call me at 555-123-4567 or 555-987-6543

Output Format

Matches are displayed with:
  1. Match number - Sequential index
  2. Matched text - The captured string
  3. Position - Character offset in the input
  4. Capture groups - Named groups labeled as g1, g2, etc.
#1 "555-123-4567" @ 11
#2 "555-987-6543" @ 28

Examples

Extract US phone numbers.Pattern:
\d{3}-\d{3}-\d{4}
Test String:
Contact: 555-123-4567 (office) or 555-987-6543 (mobile)
Output:
#1 "555-123-4567" @ 9
#2 "555-987-6543" @ 35

Implementation Details

From lib/tools/engine.ts:438-453:
case 'regexp-tester': {
  const validFlags = /^[gimsuy]*$/.test(action) ? action : 'gm';
  const flags = action === 'default' ? 'gm' : validFlags;
  
  let regex: RegExp;
  try {
    regex = new RegExp(input, flags);
  } catch (e) {
    return { output: `Invalid regular expression: ${e.message}` };
  }
  
  const test = options.secondInput ?? '';
  const matches = [...test.matchAll(regex)].map((m, i) => {
    const groups = m.slice(1)
      .map((g, idx) => `g${idx + 1}=${g ?? ''}`)
      .join(', ');
    return `#${i + 1} "${m[0]}" @ ${m.index ?? 0}${
      groups ? ` (${groups})` : ''
    }`;
  });
  
  return { output: matches.length ? matches.join('\n') : 'No matches' };
}

Common Patterns

URL Matching

https?://[^\s]+

Hex Colors

#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3}

IP Addresses

\b(?:\d{1,3}\.){3}\d{1,3}\b

Date (YYYY-MM-DD)

\d{4}-\d{2}-\d{2}

HTML Tags

<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)

Credit Card (Simple)

\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}

Character Classes

PatternMatches
\dAny digit (0-9)
\DAny non-digit
\wWord character (a-z, A-Z, 0-9, _)
\WNon-word character
\sWhitespace (space, tab, newline)
\SNon-whitespace
.Any character (except newline)
[abc]Any of a, b, or c
[^abc]Anything except a, b, or c
[a-z]Lowercase letters

Quantifiers

PatternMatches
*0 or more
+1 or more
?0 or 1 (optional)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times

Anchors

PatternMatches
^Start of string/line
$End of string/line
\bWord boundary
\BNon-word boundary

Common Mistakes

Escaping Special Characters: Remember to escape special regex characters like ., *, +, ?, [, ], {, }, (, ), |, \, ^, $Example: Use \. to match a literal period

Greedy vs Non-Greedy

<.*>     # Greedy: matches <b>test</b> more</b> as one match
<.*?>    # Non-greedy: matches <b>, </b>, </b> separately

Case Sensitivity

By default, regex is case-sensitive. Use the i flag for case-insensitive matching:
test     # Matches: test
test (i) # Matches: test, Test, TEST, TeSt

Testing Strategy

  1. Start simple - Test basic patterns before adding complexity
  2. Test edge cases - Empty strings, special characters, very long inputs
  3. Use capture groups - Extract specific parts of matches
  4. Check performance - Avoid catastrophic backtracking with complex patterns
  5. Validate thoroughly - Test with both valid and invalid inputs

Build docs developers (and LLMs) love