(?=...) is a positive lookahead assertion. It succeeds only when the text right after the current position does match the inner pattern. It is zero-width—it peeks ahead without consuming characters or including them in the match.
Remember
(?=pattern) → "followed by pattern"
/foo(?=bar)/
"foobar" → "foo" ✓
"foobaz" → null ✗
"foo" → null ✗
zero-width: match result never includes the lookahead text
contrast: (?!...) negative lookahead (must NOT follow)
Place the lookahead right after the text you want to keep.
Write the part you want to match (e.g. foo or \d+).
Add (?=required) immediately after it.
Call test, match, or replace — the required text is checked but not captured.
Stack several lookaheads at the start for multi-rule checks (e.g. password rules).
Piece
Required?
Role
(?=…)
Yes
Assert what must follow
Text before it
Usual
What actually gets matched / returned
Inner pattern
Yes
The required following text
Pseudocode
Pseudocode
re = /token(?=good)/
find "token" in input
peek at the next characters (do not consume them)
if next characters match "good":
succeed with match = "token" only
else:
fail this attempt
Reference
Cheat Sheet
Keep these lookahead facts handy.
Topic
Detail
Syntax
(?=pattern)
Meaning
Followed by pattern
Width
Zero-width (peek only)
vs (?!...)
Negative: must not follow
Keep suffix out
/\d+(?= dollars)/ → digits only
Not a quantifier
Assertion, not repetition
Standard
ES3+ (universal)
Try it
Live Preview
Run common positive-lookahead patterns and see what matches.
Browser demo of (?=...) — same idea as the examples below.
Add a filter.(?= dollars) keeps a number only if that phrase follows.
Keep 5. After 5 comes dollars → assertion passes.
Skip 10. After 10 comes euros → assertion fails.
Edge Cases & Pitfalls
Check these before relying on positive lookahead.
result
Lookahead text is never captured
/foo(?=bar)/ returns "foo", never "foobar". The peek is only a condition.
name
Not a quantifier
(?=...) does not repeat characters. For repetition use +, *, or ?.
stack
Stacking at the start
/^(?=.*[A-Z])(?=.*\d).+$/ runs several peeks from the same position before matching the rest.
contrast
Need the opposite? Use (?!...)
Negative lookahead (?!...) requires the following text not to match.
Compatibility
Browser & Runtime Support
Positive lookahead (?=...) is part of core JavaScript regular expression syntax (ES3+).
✓ Baseline · ES3+
RegExp (?=...) lookahead
Supported in every browser and Node.js version. No polyfill needed for positive lookahead assertions.
99%Universal syntax
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
(?=...)Excellent
Bottom line: Safe everywhere. Use (?=...) when you must require specific following text without consuming it.
Analysis
Performance Notes
Approach
Cost
Best for
/token(?=good)/
~match + peek
Local “followed by” rules
/^(?=.*[A-Z])(?=.*\d)/
Extra scans per rule
Short form validation
Many stacked .* peeks
Can grow
Keep short; test on real input
A simple peek is cheap. Stacked whole-string rules like (?=.*digit)(?=.*upper) re-scan the input—fine for passwords, avoid stacking many heavy lookaheads on huge strings.
Not repetition: it is an assertion, not a quantifier like +.
One line: use (?=...) when you need a match only if something specific comes next.
Frequently Asked Questions
(?=...) is a positive lookahead assertion. It succeeds when the text immediately after the current position DOES match the pattern inside. It is zero-width—it checks ahead without consuming characters.
No. (?=...) is an assertion (a condition on what follows). Quantifiers like +, *, and ? repeat or optionalize the previous token. Lookahead never includes the peeked text in the match result.
(?=...) is positive lookahead—it requires the following text to match. (?!...) is negative lookahead—it requires the following text NOT to match. Both are zero-width.
Yes. Write /foo(?=bar)/. In the constructor use new RegExp('foo(?=bar)'). Positive lookahead has been supported since ES3.
Lookahead lets you require following text without including it in the match. /\d+(?= dollars)/ matches 5 in "5 dollars" but returns only "5", not "5 dollars".
Positive lookahead is core JavaScript regex syntax since ES3. It works in every browser and Node.js version.