I have sentences like this - \"this is a test. 4.55 and 5,000.\" I want to remove the period at the end of the sentences, but not between numbers. My output has to be - \"this
How about
pattern = re.compile(r'\.(\s)')
wordList = pattern.sub(r'\1', wordList)
This replaces a period followed by a space with just the space.
Try a negative lookahead:
\.(?!\d)
What this matches is any period that's not followed by a digit.
In regex, the $
special character "[matches] the end of the string or just before the newline at the end of the string"
In that case, assuming only one sentence per line, I would suggest the following:
\.$
This will match only periods that occur at the end of a string (or end of a line for multiline strings). Of course, if you cannot guarantee one sentence per line then they isn't the solution for you.