I am trying to parse the numeral content embedded in a string. The string has three possible forms:
- 'avenue\d+', where \d+ is a number with one or more digits or
- 'road\d+' or
- 'lane\d+' I tried:
re.sub(r'(?:avenue(\d+)|road(\d+)|lane(\d*))',r'\1','road12')
This code works well for the first line below, but incorrectly for the second.
re.sub(r'(?:avenue(\d+)|road(\d+)|lane(\d*))',r'\1','avenue12')
Out[81]: '12'
re.sub(r'(?:avenue(\d+)|road(\d+)|lane(\d*))',r'\1','road12')
Out[82]: ''
what am I doing incorrectly? thanks i
r'\1\2\3'. Also, the non-capturing group is superfluous, remove it.