Negative lookbehind on a capture group
You can exclude digits from the \S
class, then surround the expression
with whitespace boundrys, then viola ..
(?<!\S)(?<PreRef>[^\s\d]+):(?<Ref>\d{5})(?!\S)
https://regex101.com/r/JrU7Kd/1
Explained
(?<! \S ) # Whitespace boundary
(?<PreRef> [^\s\d]+ ) # (1), Not whitespace nor digit
: # Colon
(?<Ref> \d{5} ) # (2), Five digits
(?! \S ) # Whitespace boundary
Do you need a negative lookbehind? It's easier to just exclude digits from the PreRef
capture. [^\W\d]
will match word characters but not digits. Then you just need to add a \b
or other similar word boundary assertion to make sure what does match is a full word.
\b(?<PreRef>[^\W\d]+):(?<Ref>\d{5})