I have something like this:
text = "hey;)there"
Need this:
text = "hey ;) there"
I am doing 2 passes:
op_1 = re.sub(r'([a-zA-Z])([:;()])', r'\1 \2', text)
final_result = re.sub(r'([:;()])([a-zA-Z])', r'\1 \2', op_1)
I am sure there must be an efficient way for this.
r'(\W{2,})'do it? Then you can just replace it withr' \1 '- regex101.com/r/kM4qZ9/1{2}for "precisely two" or{2,}for "at least two".:,-and)are all matched by\W.