I have a string:
s = 'This is a number -N-'
I want to substitute the -N-
placeholder for a regular expression:
s = 'This is a number (\d+)'
So I can later use s
as a regular expression to match against another string:
re.match(s, 'This is a number 2')
However, I'm not able to get s to substitute in a regular expression that doesn't escape the slash:
re.sub('-N-', r'(\d+)', 'This is a number -N-')
# returns 'This is a num (\\d+)'
Please let me know what I'm doing wrong here. Thanks!