regex - regular expression to parse short urls -
I have a list of possible URLs on my site, such as
4
5
6
I want to be able to match all URLs like 6 and want to redirect them to
But I I do not want to redirect. 5 url
I tried to do something like this - ((*. * People | Groups) group)) \ r
Something is wrong. Any help? Thank you
You should check that this is not people
(group! Group) group (. *)
Right now you are seeing that regular expression What language / framework you are using by people
or groups
Can not be done on the basis to make sure that you are matching the whole string,
^
and $ < / Code> Use: ^ (?! People | group) (. *) $
You should also consider whether you Want to match URL, which starts with people
, like http://dev.site.com/People2/
. So it can be better:
^ (?? (?: People | group) (?: / | $)) (. *) $
< P> Checks that a negative match URL for the people
or groups
is done after the end of the URL or slash. You want to make sure you do not match the empty string, so use . instead of
. *
:
^ (?? (?: People | group) (?: / | $)) (. +) $
And if you want the word without any slash:
^ (? (?: People | group) (?: / | $)) ([^ /] +) $
Comments
Post a Comment