问题描述
我想在标点符号之后检测缺少的空格,并在标点符号之前检测出多余的空格。我试图使用正则表达式来匹配[A-Za-z0-9][?.,:!][A-Z]
和[A-Za-z0-9]\s+[?.,:!]
,但是当将它们应用于字符串None
时,它们都返回Something is in the air tonight.Or is it ?
。
import re
mystring = "Something is in the air tonight.Or is it ?"
missing_space_regex = re.compile('[A-Za-z0-9][?.,:!][A-Z]')
print(missing_space_regex.match(mystring))
extra_space_regex = re.compile('[A-Za-z0-9]\s+[?.,:!]')
print(extra_space_regex.match(mystring))
我意识到上面的extra_space_regex
不会检测到文本以标点符号开头的情况,但是我可以将其作为特殊情况来处理。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)