Say I have a string:
"the quick brown fox jumped over the moon.this text needs to be removed."
I am trying to remove ".this text needs to be removed." using Python.
I have tried multiple ways to do this, mainly consisting of \w+(\..*\.), but it does not work. I need a general way to remove this last part, since the text is different per file, so something like re.sub('\.this text needs to be removed\.', '', string) will not work for me.
Your regex should look like this:
This will ensure that
re.subonly matches the text between periods at the end of the string. Without the$, it will match any set of matching periods in the string.EDIT
If you want to capture everything between dots:
\..*\.