What it does
Quantifiers repeat the item before them. A trailing ? makes them lazy: as few repetitions as possible.
How to use it
- Load the example: a+? on aaa.
- Remove the ? to see the greedy result.
- Check the counterexample.
Verified example
Example
Text "aaa"
a+? Result: "a", "a", "a"
a+? Result: "a", "a", "a"
a+? Result: "a", "a", "a"
a+? Result: "a", "a", "a"
Counterexample
Text "bbb"
a+? Result: no match
a+? Result: no match
a+? Result: no match
a+? Result: no match
Recorded by running fixture FX-S03 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
- Greedy and lazy quantifiers behave the same in all four engines for this example.
Limits
- Lazy does not mean shortest overall match; it means fewest repetitions at the current position.