我对正则表达式不太熟悉。
我正在尝试创建一个正则表达式,它将匹配第一组两个转发斜杠之间的文本。最简单的就是展示一个例子。
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
非常感谢你们!
答案 0 :(得分:1)
尝试使用javascript或php preg_match:^\/([^\/]*)
模式只匹配在开头有斜杠,然后匹配不是斜杠的所有内容。