开发者

Regex pattern for matching url

i have the following pattern : /^\/(?P<slug>.+)$/ that match : /url.

My problem is that it also match /url/page, how to ignore /in this regex ?

The pattern should:

Thanks in advance.


This should do it:

/^\/(?P<slug>[^\/]+)$/

[^\/] matches every character that is not a slash (^ at the beginning of a character class negates the class). I recommend to have a look at http://www.regular-expressions.info/ to learn more about regular expressions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜