Regular expression: match start or whitespace
\b
is word boundary, which can be a white space, the beginning of a line or a non-alphanumeric symbol (\bGBP\b
).
Use the OR "|
" operator:
>>> re.sub(r'(^|\W)GBP([\W\d])', u'\g<1>£\g<2>', text)
u'\xa3 5 Off when you spend \xa375.00'