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_匹配尝试此选项:
^\/([^\/]*)
该模式仅在开头有斜杠时匹配,然后匹配所有非斜杠的内容