Following the question here I'm trying to replace a hyphen if it does not appear in a US postal code.
The logic is:
- Dont match hyphen in between digits
- Match hyphen
I've tried to acheive this using:
import re
p = re.compile(r'(?!\d+\-\d+)-') # regex here
test_str = "12345-4567 hello-you"
re.sub(p, " ", test_str)
- Expected output:
12345-4567 hello you - Actual Output:
12345 4567 hello you
What am I doing wrong?