intoxicated_curveball
asked on
Help with regular expression for URL rewrite
Hello, I can't seem to get this regex working the way I want...
The pattern is pretty simple:
^page/([0-9]+)?/?([0-9]+)? /?
So the URI can be page/1/2/ or page/1/2 or page/1/ or page/1 (or just page/)
But the capture group is not right sometimes.
For page/1/2/ it works okay,
-The 1st capture group is 1
-The 2nd capture group is 2
But for page/1/
- The 1st capture group is nothing
- The 2nd capture group is 1
It should be the 1st capture group is 1 and the 2nd capture group is nothing!
What am I doing wrong?
The pattern is pretty simple:
^page/([0-9]+)?/?([0-9]+)?
So the URI can be page/1/2/ or page/1/2 or page/1/ or page/1 (or just page/)
But the capture group is not right sometimes.
For page/1/2/ it works okay,
-The 1st capture group is 1
-The 2nd capture group is 2
But for page/1/
- The 1st capture group is nothing
- The 2nd capture group is 1
It should be the 1st capture group is 1 and the 2nd capture group is nothing!
What am I doing wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, seems to work!!!!!!!!!!!
You could try a different expression. The following creates a named group called "pagenum" that is expected to repeat 1 or 2 times. Your match.Groups["pagenum"] reference would then have one or two captures in it.
^page(?:/(?<pagenum>[0-9]+