Regex 正则表达式:如果链接仅包含特定字符串,则匹配
这是我的正则表达式:Regex 正则表达式:如果链接仅包含特定字符串,则匹配,regex,Regex,这是我的正则表达式: \/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。如何解决这个问题 您可以使用此正则表达式: /\/web
\/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
。如何解决这个问题
您可以使用此正则表达式:
/\/web[^,:]*?spec\.\w+/
您可以使用正向前瞻,如下所示:
\/web[^,:]*\.(?=spec).*\w+
匹配中必须出现什么字符串?再举一些例子。你的问题措词不好。你需要解释为什么你期望某些东西而忽略其他东西。
/\/web[^,:]*?spec\。\w+//code>@anubhava,请回答。我将投票。谢谢