开发者

Regex pattern for matching url

开发者 https://www.devze.com 2023-03-31 19:28 出处:网络
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 ?

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

精彩评论

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