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 Groups :

  (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

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -