2016-01-13 37 views
1

Regex - Find all matching words that that don't begin with a specific prefix类似的开始,也可以是类似Regex for matching whole words that contain dots正则表达式 - 寻找匹配的词和点不以前缀

我需要找到一个不以“com.”启动“somehost”的所有实例

具体来说,我期待改变“某”的情况下,在address而不是contract

<endpoint address="https://subsite.somehost.com/someservice.svc" ... 
    contract="com.somehost.subsite.someservice.MyServiceSoap" /> 
<endpoint address="https://othersub.somehost.com/anotherservice.svc" ... 
    contract="com.somehost.othersub.anotherservice.MyOtherServiceSoap" /> 

适应T中的“(未女孩)朋友”的例子他first linked question,我已经试过:

\b(?!com\.)[\w\.]*somehost\b 

将匹配subsite.somehostothersub.somehost.somehost,也不会在所有帮助,如果我想只需更换somehost部分。貌似期(.)被拧的事情了......

(在我的情况,我有机会获得lookbehinds)

回答

1

您可以使用该负回顾后:

[\w-]+\.(?<!com\.)somehost(?:\.[\w-]+)+ 

RegEx Demo

即使用只是在你的模式somehost之前回顾后(?<!com\.)