I want to replace dashes which appear between letters with a space using regex. For example to replace ab-cd
with ab cd
The following matc
re.sub()
always replaces the whole matched sequence with the replacement.
A solution to only replace the dash are lookahead and lookbehind assertions. They don't count to the matched sequence.
new_term = re.sub(r"(?<=[A-z])\-(?=[A-z])", " ", original_term)
The syntax is explained in the Python documentation for the re module.