本文介绍了在python句子结尾处删除句点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的句子-这是一个测试.4.55和5,000."我想删除句子结尾处的句点,但不要删除数字之间的句点.我的输出必须是-这是测试4.55和5,000"我尝试了以下选项,但未获得所需的输出:
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 is a test 4.55 and 5,000"I tried the below options, but not getting the required output:
wordList = "this is a test. 4.55 and 5,000."
pattern3 = re.compile("[^\w\d]+")
wordList = pattern3.sub(' ',wordList)
还尝试了以下2种方法:
Also tried the below 2:
pattern3 = re.compile("[^\w]|^[0-9]\.[0-9]")
pattern3 = re.compile("[^\w]|^([0-9]/.[0-9]+)")
我不知道我要去哪里.有人可以给我一些指示吗?我搜索了较早的帖子并进行了尝试,但它们不适用于我的情况.
I don't know where I am going wrong. Can someone give me some pointers? I searched the earlier posts and tried them, but they are not working for my situation.
推荐答案
尝试否定前瞻:
\.(?!\d)
此匹配项是任何不带数字的句点.
What this matches is any period that's not followed by a digit.
这篇关于在python句子结尾处删除句点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!