Skip to main content
ilovecalcs logoilovecalcs.

Dev · Live

Regex Tester & Explainer, pattern to English, instantly.

Write a regular expression, toggle flags, paste test text, and see matches highlighted inline in real-time. Every token is broken down with a plain-English explanation and a clickable cheatsheet for quick insertion.

How it worksReal-time
//gi
Flags

Test String

4 matches

Match Breakdown

#MatchStartEnd
1support@example.com928
2sales@company.org3047
3admin@test.co.uk89105
4user+tag@gmail.com107125

Syntax Breakdown

[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}
[A-Za-z0-9._%+-]Any char in [A-Za-z0-9._%+-]
+1 or more — greedy
@Literal "@"
[A-Za-z0-9.-]Any char in [A-Za-z0-9.-]
+1 or more — greedy
\.Escaped "."
[A-Za-z]Any char in [A-Za-z]
{2,}At least 2 times

Quick Reference

Click any token to insert at cursor

Anchors

Character Classes

Quantifiers

Groups & Alternation

Lookarounds

Escaped Chars

Field guide

How regular expressions work.

A regular expression (regex) is a pattern that defines a search rule for strings. It is built into virtually every programming language and is the standard tool for validation, parsing, search, and transformation tasks. The syntax is consistent across JavaScript, Python, Ruby, Go, Java, Rust, and Swift.

A regex is assembled from five kinds of constructs: literals that match themselves, character classes that match a category of character, quantifiers that control repetition, anchors that assert a position without consuming characters, and groups that capture sub-matches.

Character classes

A character class matches any single character from a defined set. The shorthand classes cover common sets: \d matches any digit (0–9), \w matches any word character, and\s matches any whitespace. Their uppercase counterparts match the complement. Custom classes use square brackets:[aeiou] matches any vowel, [^0-9] matches anything that is not a digit.

Quantifiers: greedy and lazy

Quantifiers control how many times the preceding element must appear. By default they are greedy — they consume as many characters as possible. Adding ? after a quantifier makes it lazy, matching as few characters as possible.

The pattern <.+> on the string <a>click</a> matches the entire string (greedy). The lazy pattern <.+?> matches<a> and then </a> separately.

Anchors and boundaries

Anchors do not consume characters — they assert a position.^ asserts the start of the string, $asserts the end, and \b asserts a boundary between a word character and a non-word character.

Capture groups and named groups

Parentheses create a capture group. When the pattern matches, the text inside each group is available separately. Named groups use(?<name>...) syntax. Non-capturing groups(?:...) group without recording.

Lookarounds

Lookarounds assert context without consuming characters.(?=abc) asserts that what follows matches;(?!abc) asserts that it does not.(?<=abc) and (?<!abc) look behind the current position.

Flags

  • g — Global: find all matches instead of stopping after the first.
  • i — Case insensitive: [a-z] also matches A–Z.
  • m — Multiline: ^ and $ match line boundaries.
  • s — DotAll: . matches newline characters too.

Common mistakes

  • Unescaped metacharacters. To match a literal dot, write \.. The characters . * + ? ^ $ { } [ ] | ( ) \ must all be escaped to match literally.
  • Missing the g flag. Without it, most APIs return only the first match.
  • Catastrophic backtracking. Nested quantifiers on overlapping patterns like (a+)+ can cause exponential processing time on certain inputs.