Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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 使用正则表达式进行URL筛选:仅查找字符串的第一个实例,但不查找前缀为其他特定字符串的实例_Regex - Fatal编程技术网

Regex 使用正则表达式进行URL筛选:仅查找字符串的第一个实例,但不查找前缀为其他特定字符串的实例

Regex 使用正则表达式进行URL筛选:仅查找字符串的第一个实例,但不查找前缀为其他特定字符串的实例,regex,Regex,我需要能够识别URL中内容的第一个实例 但不是在第一个实例之前包含wwwroot的。 我不希望它找到任何后续的内容实例 并且需要它的所有方面都不区分大小写 i、 e.只需在这些URL中查找第一个内容: https://localhost/dfkdfjkdfjkdfkj/Content/dfdfdfdf.png https://localhost/wwwrootExtra/Content/dfdfdfdf.png https://localhost/dfkdfjkdfjkdfkj/ConTent/

我需要能够识别URL中内容的第一个实例 但不是在第一个实例之前包含wwwroot的。 我不希望它找到任何后续的内容实例 并且需要它的所有方面都不区分大小写

i、 e.只需在这些URL中查找第一个内容:

https://localhost/dfkdfjkdfjkdfkj/Content/dfdfdfdf.png
https://localhost/wwwrootExtra/Content/dfdfdfdf.png
https://localhost/dfkdfjkdfjkdfkj/ConTent/Images/ConTent/Patrol.png
https://localhost/MangoTrunkDebug/wwwRoot/ConTent/dffddf.png
https://localhost/MangoTrunkDebug/wwwRoot/ConTent/Images/ConTent/Patrol.png
并且在这些URL中找不到任何内容实例:

https://localhost/dfkdfjkdfjkdfkj/Content/dfdfdfdf.png
https://localhost/wwwrootExtra/Content/dfdfdfdf.png
https://localhost/dfkdfjkdfjkdfkj/ConTent/Images/ConTent/Patrol.png
https://localhost/MangoTrunkDebug/wwwRoot/ConTent/dffddf.png
https://localhost/MangoTrunkDebug/wwwRoot/ConTent/Images/ConTent/Patrol.png
我已经做到了这一点,但现在正在努力:

(?<!(?i)\/wwwroot)\/(?i)Content\/
(?
这仍然会选择第一个实例之外的内容

非常感谢您的帮助

用途:

由于断言
(?)在两种情况下都有效,因此您将获得2个匹配项

一个选项是在匹配
/Content/
之前不匹配
/wwwroot/
/Content/
,并捕获捕获组中的第一个匹配项

您可以在工具或编程语言中启用不区分大小写,或将
(?i)
添加到模式中

^https?://(?:(?!/(?:wwwroot|Content)/).)*/(Content)/
  • ^
    字符串的开头
  • https?://
    匹配http部分
  • (?:
    非捕获组
    • (?!/(?:wwwroot | Content)/)*
      匹配直接后跟wwwroot或Content的任何字符
  • /(内容)/
    匹配
    /
    ,捕获组1中的内容并匹配
    /

另一种选择是在lookback中使用量词

(?

由于断言
(?)在两种情况下都有效,因此您将获得2个匹配项

一个选项是在匹配
/Content/
之前不匹配
/wwwroot/
/Content/
,并捕获捕获组中的第一个匹配项

您可以在工具或编程语言中启用不区分大小写,或将
(?i)
添加到模式中

^https?://(?:(?!/(?:wwwroot|Content)/).)*/(Content)/
  • ^
    字符串的开头
  • https?://
    匹配http部分
  • (?:
    非捕获组
    • (?!/(?:wwwroot | Content)/)*
      匹配直接后跟wwwroot或Content的任何字符
  • /(内容)/
    匹配
    /
    ,捕获组1中的内容并匹配
    /

另一种选择是在lookback中使用量词

(?