Reputation: 36
I'm trying to trap URLs of the following structure:
/resources/state-name/city-name
given that there are URLs of the following type
/resources/other-words
/resources/state-name
/resources/state-name/city-name/other-words
I have tried to trap using include/matches regex:
\/resources\/.*\/.*
exclude/matches regex:
\/resources\/.*\/.*\/.*
but this is allowing the other-words and state-name only to slip through.
Upvotes: 1
Views: 190
Reputation: 7081
Try this regex \/resources\/[^\/\r\n]*(?:$|(?:\/.*\/.*$))
. I assumed the end of the url was also the end of the line. This matches all of them but /resources/state-name/city-name
To only get /resources/state-name/city-name
, then use this one \/resources\/[^\/\r\n]*\/[^\/\r\n]*$
.
Upvotes: 1
Reputation: 942
Something like this /(\/resources\/)([\w+%-]+)\/([\w+%-]+)/g
With this [\w-%]
you match any letter, number, - and % in the URL (i put % because in the URLs spaces are replaced with -
or +
or %20
)
Also, with the ()
you can access each member with $1
to $3
Upvotes: 0