Remove periods at the end of sentences in python

后端 未结 3 1851
别那么骄傲
别那么骄傲 2021-01-21 01:16

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

3条回答
  •  攒了一身酷
    2021-01-21 02:03

    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.

提交回复
热议问题