I’m completely unexperienced with regex, so I apologise if this is a simple question, but I’ve been unable to find any answers anywhere. I’m trying to match strings of the form [some numbers] [some letters] such as 123 apples but I don’t want to match them when they are preceeded by the word about (e.g. about 10 apples should not match).
I’ve tried using (?<!about )(\d[,\.\d]*) ([a-zA-Z]+) but that obviously doesn’t work as it just moves the match on somewhat (such that about 12 apples matches as 2 apples). What can I do to solve this?
I’ve had this problem before. Try this:
The
\bmatches a zero-character word boundary (space followed by alphanumeric or vice-versa). It will refuse to match “about 123 apples” as “23 apples”, because there’s no word boundary immediately before the “2”.