I am stuck on this rather simple regex string issue for hours.
I have a string and I need to remove the left side of text in all occurrence of hyphen "-" or curved brackets "()"
I am able to remove the brackets but I can’t figure out how to remove the hyphen as well.
Below is my attempt
import re
sentence = re.sub(r"\([^()-]*\)", "", 'P. Test data-I am using-(regex)(python)')
print(sentence)
Output
P. Test data-I am using-
The output I need is
P. Test data
Thank you for your help.
>Solution :
You can use str.partition:
>>> 'P. Test data-I am using-(regex)(python)'.partition('-')[0]
'P. Test data'