Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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 具有部分URI的正则表达式_Regex - Fatal编程技术网

Regex 具有部分URI的正则表达式

Regex 具有部分URI的正则表达式,regex,Regex,我对正则表达式不是很熟悉 我正在尝试创建一个正则表达式,它将匹配第一组斜杠之间的文本。举个例子最简单 Search Texts: /index /index/ /index/foo/ /index/foo/bar/ All of those should return just "index" 另一个例子: Search Texts: /page.php /page.php/foo?bar=1 Should return just "page.php" for both of those 谢

我对正则表达式不是很熟悉

我正在尝试创建一个正则表达式,它将匹配第一组斜杠之间的文本。举个例子最简单

Search Texts:
/index
/index/
/index/foo/
/index/foo/bar/
All of those should return just "index"
另一个例子:

Search Texts:
/page.php
/page.php/foo?bar=1
Should return just "page.php" for both of those

谢谢大家

为javascript或php preg_匹配尝试此选项:
^\/([^\/]*)

该模式仅在开头有斜杠时匹配,然后匹配所有非斜杠的内容