代码之家  ›  专栏  ›  技术社区  ›  Sam

正则表达式:如果链接仅包含特定字符串,则匹配

  •  -1
  • Sam  · 技术社区  · 7 年前

    \/web[^,:]*\.\w+
    

    /web/src/app/reports/allLogs/test-list/test-event-history-list.component.spec.ts
    

    但不是这个:

    /web/src/app/reports/allLogs/test-list/test-event-history-list.component.ts
    

    目前这两个都匹配,但我想包含 spec . 如何解决这个问题?

    Link to the example.

    2 回复  |  直到 7 年前
        1
  •  1
  •   anubhava    7 年前

    您可以使用此正则表达式:

    /\/web[^,:]*?spec\.\w+/
    

    Updated RegEx Demo

        2
  •  1
  •   Hamed Zarei    7 年前

    您可以使用正向前瞻,如下所示:

    \/web[^,:]*\.(?=spec).*\w+