2016-01-13 38 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\.)