【问题标题】:Regex - Find matching words AND dots that don't begin with prefix正则表达式 - 查找不以前缀开头的匹配单词和点
【发布时间】:2016-01-14 00:21:44
【问题描述】:

类似于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 中的“somehost”实例,而不是 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" />

改编first linked question中的“(不是女朋友)朋友”的例子,我试过了:

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

将匹配subsite.somehostothersub.somehost.somehost,如果我只想替换somehost 部分,这也没有任何帮助。看起来那个时期(.)把事情搞砸了......

(在我的情况下,我确实可以访问lookbehinds)

【问题讨论】:

    标签: regex


    【解决方案1】:

    您可以使用这种消极的向后看:

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

    RegEx Demo

    即在你的模式中使用(?&lt;!com\.) 之前的lookbehind somehost

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-10
      • 2013-11-23
      • 2013-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多