I'm trying to substitute all chars inside ()
alongside with what's inside them but there is a problem. In the output it leaves whitespaces at start and end.
Code:
import re
regex = r"\(.+?\)"
test_str = ("(a) method in/to one's madness\n"
"(all) by one's lonesome\n"
"(as) tough as (old boot's)\n"
" (at) any moment (now) \n"
"factors (in or into or out) \n"
" right-to-life\n"
"all mouth (and no trousers/action)\n"
"(it's a) small world\n"
" throw (someone) a bone ")
subst = ""
result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
if result:
print (result)
Result:
method in/to one's madness
by one's lonesome
tough as
any moment
factors
right-to-life
all mouth
small world
throw a bone
I tried different patterns (other than this) to remove the \s
from start but then when it finds the space at the end of any line it combines the following lines to the preceding one's.