Reputation: 24325
I am trying to do a url rewrite but can't capture the correct action for two scenarios. The first is if the action is "scheduletable
", only capture "schedule
" in "action
", otherwise capture the whole thing "pools
". My regex keeps including the "table
" in the "action
"
^/events/(?<action>.*)(?table)?/(?<eventid>\d*).*$
The original URL
/events/scheduletable/39?layout=time&type=all
/events/pools/39
Upvotes: 1
Views: 71
Reputation: 2427
Consider the following Regex...
(?<=events/).*?(?=(table|/))
Good Luck!
Upvotes: 0
Reputation: 56536
You had a ?
in the wrong place. (?table)
doesn't make sense, and your *
on action
needs to be non-greedy (.*?
instead of .*
). Try this;
^/events/(?<action>.*?)(table)?/(?<eventid>\d*).*$
Upvotes: 0
Reputation: 4795
Use:
^/events/(?<action>.*?)(?:table)?/(?<eventid>\d*).*$
And use $1
and $2
in the replacement - or your group names even.
Upvotes: 2