RegexWars
Tier 2 · Archmageextract

Not A Price

Extract every number that is not a dollar amount — that is, not preceded by a $.

A negative lookbehind (?<!...) succeeds when what precedes the current position is NOT the given text. The obvious answer, (?<!\$)\d+, is wrong in a way worth seeing: it is blocked at the 1 of $100, then simply starts again at the 0 and happily returns "00". The assertion has to exclude the middle of a number as well as the currency symbol. Then note that the pence are still part of the price. Excluding a digit is not enough once a decimal point is involved, because the 5 of $12.50 is preceded by a point, not a digit — and a lookbehind of variable length is what lets you look back past both.

Your pattern1 chars · par 17
//g
Flags
Start typing — tests run as you go.0 of 5 visible tests passing
Test cases
  • costs $30 and takes 45 minutes→ ["45"]
  • pay $9 or wait 10 days→ ["10"]
  • $100→ []

    not "00"

  • 7 items→ ["7"]
  • costs $12.50 and 3 more→ ["3"]

    the pence are still part of the price

+ 5 hidden tests, checked when you submit. They are what stops a pattern that only fits the examples above.