What it does
Lookahead and lookbehind check what is next to a position without including it in the match.
How to use it
- Load the example: (?<=ID=)\d+ matches 42 without ID=.
- Check the counterexample.
- Switch to Go to see that it rejects lookaround.
Verified example
Example
Text "ID=42 code=9"
(?<=ID=)\d+ Result: "42"
(?<=ID=)\d+ Result: "42"
(?<=ID=)\d+ Result: "42"
Counterexample
Text "code=9"
(?<=ID=)\d+ Result: no match
(?<=ID=)\d+ Result: no match
(?<=ID=)\d+ Result: no match
Recorded by running fixture FX-S06 on : rp.js@1 on Node v24.21.0 (V8), v24.21.0, CPython 3.14.2 (Pyodide 314.0.7), PCRE2 10.48, go1.27.1. JavaScript results come from the rp.js@1 core on Node’s V8; your browser runs the same core.
Engines
- Go regexp does not support lookaround. Python re and PCRE2 require fixed-length lookbehind.
Limits
- This fixed-length example does not show that variable-length lookbehind works everywhere.