Regular Expression

//g

Test String

How to Use the Regex Tester

Enter a regular expression pattern in the pattern field, toggle the flags you need, then paste your test string in the text area. Matches are highlighted in real time — each match shows its index position and any capture groups.

What is a Regular Expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. It is used for string searching, validation, and text manipulation in virtually every programming language. Regex patterns can match literal text, character classes, repetitions, anchors, and more.

Common Regex Patterns

  • Email[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
  • URLhttps?://[^\s/$.?#].[^\s]*
  • IPv4 address(\d{1,3}\.){3}\d{1,3}
  • Date (YYYY-MM-DD)\d{4}-\d{2}-\d{2}
  • Hex color#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})
  • Digits only^\d+$
  • Whitespace (any)\s+
  • Word boundary\bword\b

Regex Cheat Sheet

Anchors

  • ^ — Start of string (or line in multiline mode)
  • $ — End of string (or line in multiline mode)
  • \b — Word boundary
  • \B — Not a word boundary

Quantifiers

  • * — 0 or more
  • + — 1 or more
  • ? — 0 or 1 (also makes quantifiers lazy)
  • {n} — Exactly n times
  • {n,m} — Between n and m times

Character Classes

  • \d — Digit (0-9)
  • \w — Word character (a-z, A-Z, 0-9, _)
  • \s — Whitespace (space, tab, newline)
  • [abc] — Any of a, b, or c
  • [^abc] — Any character except a, b, or c

Groups

  • (abc) — Capture group
  • (?:abc) — Non-capturing group
  • (?<name>abc) — Named capture group
  • (?=abc) — Positive lookahead
  • (?!abc) — Negative lookahead

Regex Flags

  • g (global) — Find all matches instead of stopping after the first one.
  • i (case insensitive) — Match letters regardless of case.
  • m (multiline) — Make ^ and $ match the start and end of each line instead of the whole string.
  • s (dot all) — Make . match newline characters as well.

Debugging Tips

  • Start simple — Build your pattern incrementally. Match a literal string first, then add character classes and quantifiers.
  • Use non-greedy quantifiers — Replace .* with .*? to avoid over-matching.
  • Escape special characters — Characters like . * + ? ( ) [ ] { } ^ $ | \ must be escaped with \ to match literally.
  • Check your flags — Forgetting the g flag is the most common reason only the first match is returned.

Related Guides

FAQ

Is my data safe?

Yes. All regex testing happens entirely in your browser using JavaScript. No data is sent to any server.

Which flags are supported?

The tool supports g (global), i (case insensitive), m (multiline), and s (dot all) flags. You can combine multiple flags.

Why does my regex match unexpectedly?

Common pitfalls include forgetting to escape special characters like . * + ? ( ) [ ] { } ^ $ | \, or not using the global flag when you expect multiple matches.

What is a capture group?

A capture group is a part of the pattern wrapped in parentheses (). It lets you extract specific parts of a match. For example, (\d+)-(\d+) applied to 2024-01 captures 2024 and 01 as separate groups.

How do I match a literal dot?

Use \. instead of .. In regex, an unescaped dot matches any character. To match a literal period — for example in a file extension or IP address — you must escape it: \.txt or \d+\.\d+\.\d+\.\d+.

Related Articles