I need to remove the hyphens between lowercase letters only. This is the expression that I have currently:
re.sub(\'\\[a-z]-\\[a-z]\', \"\", \'hyphen-ated Asia-P
re.sub(r'([a-z])-([a-z])', r'\1\2', "hyphen-ated Asia-Pacific 11-12")
Captures the letters before and after the hyphen and preserves them when stripping the hyphen. \1
and \2
denotes the first and second captured group, which are the letters in this case.
Your current code matches the two letters around the hyphen and removes the whole match. You should preserve the letters when substituting.