Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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: /this/that/ 除: /this/that/99-text 这就是我所尝试的: /this/that/ ^www.domain.com//this/that/99-text 使用消极前瞻: $URI="/this/that/99-text"; if( preg_match_all("#/this/that(?!/99-text)#", $URI,$matches) ) { var_dump($matches); } else

如何编写正则表达式以包含所有包含以下内容的URL:

/this/that/
除:

/this/that/99-text
这就是我所尝试的:

/this/that/
^www.domain.com//this/that/99-text

使用消极前瞻:

$URI="/this/that/99-text";

if( preg_match_all("#/this/that(?!/99-text)#", $URI,$matches) )
{
  var_dump($matches);
}
else
{
 echo 'No matches found.';
}
试试这个:

\/this\/that\/(?!99-text)

它使用一个负前瞻,以确保后面没有
99个文本

如果您希望在
/this/that
之后使用可选的正斜杠,可以执行以下操作:

\/this\/that\/?(?!\/?99-text)

另外,如果有类似于
/this/that99 text
的内容是有效的,您可以执行以下操作:

\/this\/that(?:\/(?!99-text)|(?!\/99-text))

谢谢,我试过(?99 \-text)/this/that,但它不起作用(它包括包含/this/that/的所有内容)。非常感谢,这似乎是一个简单的问题,但我一直在努力解决它。第二个建议很有效!