I just don’t seem to have any luck with regular expressions ! I’ve written a WordPress plugin which grabs (in theory) a category and an optional page number from a url but I just can’t get it to match the url pattern.
The url’s are of the format:
Bikes/Hybrid-Bikes
Bikes/Hybrid-Bikes/1
Bikes/Hybrid-Bikes/2
etc
and:
Bikes/Mountain-Bikes
Bikes/Mountain-Bikes/1
Bikes/Mountain-Bikes/2
and so on.
Here’s the regex I’m trying to use:
Bikes/([^/]+)(?:/(\d+))?
which matches the category but not the page number. I’m sure I’m 99% of the way there but I just can’t figure this out !
Thanks in advance
Phil
You were very close indeed.
Add the start and end (
^$) markers to complete the expression:PHP working example: