No Login Data Private Local Save

Regex Lookaround Tester - Online Experiment with Lookahead

5
0
0
0

Regex Lookaround Tester

Experiment with lookahead & lookbehind assertions in real-time

(?=...) (?!...) (?<=...) (?<!...) — Zero-width assertions that check context without consuming characters

/ /
Flags:
0 matches
Enter a regex and test text to see highlighted matches...
# Match Position Length Capture Groups
No matches yet. Try adjusting your regex or test text.
Lookaround Breakdown

Enter a regex with lookaround assertions to see an automatic breakdown of each lookaround component.

Frequently Asked Questions
What is a lookahead assertion?

A lookahead (?=...) checks if the text after the current position matches a pattern, without consuming characters. It's a zero-width assertion—it inspects but doesn't "eat" the text. Negative lookahead (?!...) ensures the pattern does not follow.

What is a lookbehind assertion?

A lookbehind (?<=...) checks if the text before the current position matches a pattern, without consuming characters. Negative lookbehind (?<!...) ensures the pattern does not precede. Supported in ES2018+ (Chrome 62+, Firefox 78+, Safari 16.4+).

Why are they called "zero-width"?

Because lookaround assertions match a position in the text, not actual characters. They don't add to the match length—they simply check a condition at that spot. The regex engine "looks around" without moving its cursor.

Can lookarounds contain capture groups?

Yes! Groups inside lookarounds can capture text. For example, (?=(foo)\d+) will capture "foo" in group 1 even though the lookahead itself doesn't consume characters. This is useful for extracting context-dependent data.

What are common use cases?

Password validation (must contain digit, uppercase, symbol), string extraction (get text between delimiters), find & replace (match only when surrounded by specific context), and text parsing where context matters but shouldn't be part of the match.

Browser compatibility for lookbehind?

Lookbehind was added in ES2018. It's supported in Chrome 62+, Edge 79+, Firefox 78+, Node.js 8.10+, and Safari 16.4+. Older browsers (especially Safari < 16.4) will throw a SyntaxError. Always test with your target browsers.

Can I nest lookarounds?

Yes, you can nest lookarounds inside each other. For example: (?=(?=.*\d).{8,}). However, deeply nested lookarounds can become hard to read and debug. Use this tool to experiment and understand how they interact!