在Python中使用正则表达式消除同时具有两个或多个句点的单词?

在Python中使用正则表达式消除同时具有两个或多个句点的单词?,python,regex,Python,Regex,例如,如果我有一个字符串: "I really..like something like....that" 我只想得到: "I something" 有什么建议吗?如果你想用正则表达式;您可以使用下面的正则表达式删除它们: r"[^\.\s]+\.{2,}[^\.\s]+"g 正则表达式解释: [^\.\s]+ at least one of any character instead of '.' and a white space \.{2,} at le

例如,如果我有一个字符串:

"I really..like something like....that"
我只想得到:

"I something"

有什么建议吗?

如果你想用正则表达式;您可以使用下面的正则表达式删除它们:

r"[^\.\s]+\.{2,}[^\.\s]+"g

正则表达式解释:

[^\.\s]+       at least one of any character instead of '.' and a white space
\.{2,}         at least two or more '.'
[^\.\s]+       at least one of any character instead of '.' and a white space
或者这个正则表达式:

r"\s+[^\.\s]+\.{2,}[^\.\s]+"g
  ^^^  for including spaces before those combination

如果您想使用regex;您可以使用下面的正则表达式删除它们:

r"[^\.\s]+\.{2,}[^\.\s]+"g

正则表达式解释:

[^\.\s]+       at least one of any character instead of '.' and a white space
\.{2,}         at least two or more '.'
[^\.\s]+       at least one of any character instead of '.' and a white space
或者这个正则表达式:

r"\s+[^\.\s]+\.{2,}[^\.\s]+"g
  ^^^  for including spaces before those combination

如果要显式使用正则表达式,可以使用以下命令

import re

string = "I really..like something like....that"
with_dots = re.findall(r'\w+[.]+\w+', string)

split = string.split()
without_dots = [word for word in split if word not in with_dots]
rawing提供的解决方案也适用于这种情况

' '.join(word for word in text.split() if '..' not in word)

如果要显式使用正则表达式,可以使用以下命令

import re

string = "I really..like something like....that"
with_dots = re.findall(r'\w+[.]+\w+', string)

split = string.split()
without_dots = [word for word in split if word not in with_dots]
rawing提供的解决方案也适用于这种情况

' '.join(word for word in text.split() if '..' not in word)

您可以将边界与周围环境结合使用:

\b(?<!\.)(\w+)\b(?!\.)

您可以将边界与周围环境结合使用:

\b(?<!\.)(\w+)\b(?!\.)

它必须是正则表达式吗?为什么不
'.join(文本中的逐字逐句。如果'..'不在word中,则拆分())
?它是否适用于此字符串:
我真的..喜欢..类似于..fdsafdsf rdas…dsafaff…fdfff…ffff..
?它必须是正则表达式吗?为什么不
'.join(文本中的逐字逐句。如果'..'不在word中,则拆分())
?它是否适用于此字符串:
我真的..喜欢..像..那样的fdsafdsf rdas…dsafaff…fdfff…ffff..