python - 因为我可以在 exp reg 中格式化一个句子?

标签 python regex

我可以删除正则表达式中段落的短语“abc def”吗?考虑到它可能会以分数为前缀。

例如:

Hello, abc def, etc etc -> Hello, etc etc
abc def etc etc -> etc etc.
abd def ... etc etc -> etc etc.
Hello, abc def. Etc etc -> Helo. Etc etc

考虑到它可能包含以下字符之前或之后:,;.:

我已经尝试过这个:

msg = re.sub("\s+abc\s+def\s+", " ", msg)

但我需要创建条件评级

最佳答案

[ ]*abc\s+def\s*[,;.:]*

试试这个。查看演示。

https://regex101.com/r/uE3cC4/19#python

关于python - 因为我可以在 exp reg 中格式化一个句子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30017586/

相关文章:

python - 创建具有 2 个或更多标题行的 QTableWidget

regex - 零填充整数与 perl 正则表达式替换

java - 使用正则表达式在java中分割字符串

python - Gensim doc2vec 在 ngram 上进行训练

python - Pandas Rolling vs Scipy kurtosis - 严重的数值不准确

regex - 使用正则表达式检索字符之间的字符串

JavaScript http 正则表达式

regex - 为什么 BASH_REMATCH 不适用于引用的正则表达式?

Emacs shell-mode 中的 Python 打开 stty echo 并中断 C-d

Python Asyncio 任务取消