Reputation: 3355
I’m trying to figure out how to make;
/section/hello-news/goodbye-news
Match when this pattern is used (a single group)
/section/([a-zA-Z0-9\-]+)
But with the way I have it setup only /section/hello-news
matches. Where am I going wrong?
Upvotes: 0
Views: 41
Reputation: 98861
You missed the forward slash /
, try this:
/section/([A-Za-z0-9\/-]+)
Upvotes: 1
Reputation: 7541
You are missing the trailing /
on hello-news
, and allowing it to repeat.
/section(/[a-zA-Z0-9\-]+)+
This way, it matches any number of subdirectories. i.e. '/section/foo/bar/baz'.
If you are using the matches, you can also ignore the slash by making it non-capturing:
/section/(?:/([a-zA-Z0-9\-]+))+
Upvotes: 0
Reputation: 13888
Here is the correct regex, just add another group:
\/section\/([a-zA-Z0-9-]+)\/([a-zA-Z0-9-]+)
https://regex101.com/r/mP0wN2/1
Upvotes: 0