views:

39

answers:

2

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.

A: 

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

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

  this     is     the     path
Tomalak
A: 

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

The Real Bill