Regex Lookbehind: Match Around Without Consuming

The library's fines book: a lookbehind checks for Rp before a number without taking it. What is checked, taken and refused is marked on the board, from the…

Why it matters

Lookbehind and lookahead come up whenever you need context but do not want to carry it: the number after Rp without the Rp, a price before its unit, a find-and-replace that only applies between certain patterns. Without them, you capture and then throw the piece away yourself.

The key idea

An assertion is zero-width: it checks a neighbour without taking it

Try it in this playground