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'
More Related Contents:
- Take first some character of string but if particular character will come consider that character also
- How to extract numbers from a string in Python?
- Is it worth using Python’s re.compile?
- Extract part of a regex match
- Regular expression matching a multiline block of text
- What is the difference between re.search and re.match?
- How can I do multiple substitutions using regex?
- regex error – nothing to repeat
- How to match any string from a list of strings in regular expressions in python?
- How to timeout function in python, timeout less than a second
- Extract a string between double quotes
- Reuse part of a Regex pattern
- Find the indexes of all regex matches?
- Find out how many times a regex matches in a string in Python
- RegEx Get string between two strings that has line breaks
- Python – re.findall returns unwanted result
- Why Does a Repeated Capture Group Return these Strings?
- Splitting out the output of ps using Python
- How to use regex to find all overlapping matches
- How can a recursive regexp be implemented in python?
- Python regular expression pattern * is not working as expected
- Split string at every position where an upper-case word starts
- FutureWarning: The default value of regex will change from True to False in a future version
- Why does this take so long to match? Is it a bug?
- Regex matching – why does this not match and return None?
- How to use str.contains() with multiple expressions in pandas dataframes
- match dates using python regular expressions
- How to Fix JSON Key Values without double-quotes?
- python regular expression across multiple lines
- How to use regex with optional characters in python?