Regex Sticky Flag: Matching from lastIndex

The fines calculator at the library kiosk: exec() again and again from lastIndex. What do g and y do when they meet a character they do not know? The base of…

Why it matters

Whenever you write a parser or tokenizer of your own (a mini language, formulas, a highlighter, templates), you need "the match must be right here". A g that likes to jump lets broken input through silently. y makes "no match" mean an error at this very place.

The key idea

y anchors every try at lastIndex and refuses to jump

Try it in this playground