开发者

Match all directory names in file path with regular expression

开发者 https://www.devze.com 2023-01-03 16:10 出处:网络
Can someone give me the regular expression to match something like /this/is/the/path or /this/is/the/path/ and matches like:

Can someone give me the regular expression to match something like /this/is/the/path or /this/is/the/path/ and matches like:

$1=this
$2=is
$3=the
$4=path

([^/]+)/ 开发者_运维问答matches one, but I'm not quite sure how to get it to repeat.

FYI: this is for a mod rewrite RewriteRule match.


If you want defined, numbered groups, you must repeat it yourself:

/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?

  this     is     the     path


If mod-rewrite supports it ([^/]+){1,4} should match from 1 to 4 groups. Adapt numbers as needed/desired.

0

精彩评论

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