LOOKAROUNDS

Lookbehind

(?<=...) checks what comes before the match.

Lookbehind is the mirror image of lookahead: it checks what comes BEFORE the match. (?<=\$)\d+ matches digits only when a dollar sign sits right before them, and the $ stays out of the match. In "$40" it matches "40". (?<!...) is the negative version.

(?<=\$)\d positive lookbehind: a digit only if "$" comes right before. In "$5" matches the 5; in "5" alone matches nothing.
(?<!\$)\d negative lookbehind: a digit only if "$" does NOT come right before. In "x5" matches the 5; in "$5" matches nothing.

JavaScript lookbehind (added in ES2018) works in every current browser and in Node. Unlike some engines, it can be variable-length: (?<=\$\s*)\d+ is valid, so the part before the match need not be a fixed number of characters.

PRACTICE - 2 DRILLS 0/2 DONE
DRILL 1/2

Match amounts that come right after a dollar sign - digits only, $ excluded from the match.

/ /
pay $40 or 40 coins
must match: "40"
price: $129 today
must match: "129"
free, costs 0
must match nothing
DRILL 2/2- Issue refs

Match the number after a # (issue references), with the # excluded from the match.

/ /
fixes #42 and #7
must match: "42" "7"
see issue #1001
must match: "1001"
plain 99
must match nothing