【发布时间】:2011-07-28 13:31:11
【问题描述】:
我遇到了匹配和替换某些不包含在 http:// 中的单词的问题
当前正则表达式:
http://.*?\s+
这匹配模式http://www.egg1.com @987654321@
我需要一个正则表达式来匹配包含在 http:// 之外的某些单词
例子:
"This is a sample. http://www.egg1.com and http://egg2.com. This regex will only match
this egg1 and egg2 and not the others contained inside http:// "
Match: egg1 egg2
Replaced: replaced1 replaced2
最终输出:
"This is a sample. http://www.egg1.com and http://egg2.com. This regex will only
match this replaced1 and replaced2 and not the others contained inside http:// "
问题: 需要匹配某些模式(例如:egg1 egg2),除非它们是 http:// 的一部分。如果 egg1 和 egg2 存在于 http:// 中,则不匹配它们
【问题讨论】:
-
换句话说:您想要匹配某些模式(在您的示例中为 egg1 和 egg2)除非它们是URL 的一部分?
-
您陈述问题的方式并不重要,匹配是否来自 URL。你真正想要匹配的是什么?
-
@Ferdinand 是的..你是对的.. 如果 egg1 和 egg2 在 http:// 内,则不匹配。
-
他想在“Google 可以在
http://www.google.com”中找到“Google”,跳过网址中的“google”。 -
http:// 之后的文本没有“包含在其中”。
标签: python regex regex-negation