Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 正则表达式:如果链接仅包含特定字符串,则匹配_Regex - Fatal编程技术网

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,请回答。我将投票。谢谢