Forum Moderators: coopster

Message Too Old, No Replies

URL regex help

         

ianevans

1:49 am on Mar 13, 2008 (gmt 0)

10+ Year Member



I've said this here before...my brain goes on vacation when I try to handle regex's

I have a regex in a program that finds a group of names when they occur at the start of an URL's path_info:

^/(testgalleries¦galleries¦poll¦news¦photos)(/¦$)

This works when one of the words is in the root of the site like:

example.com/photos

How can I change it if the name can be found in any level of subdirs, e.g.

example.com/subdir/photos
example.com/subdir/subdir/photos
example.com/subdir/subdir/subdir/photos

I basically know I need to be able to search for alphanumerics, -, and / between ^/ and (testgalleries

Thanks in advance.

coopster

1:58 pm on Mar 13, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The caret symbol is exactly as you stated, an anchor to mark the beginning of the pattern to match. If you leave the caret off, it tells the expression that it needs to match the pattern anywhere in the string, not just at the beginning.

ianevans

2:04 pm on Mar 13, 2008 (gmt 0)

10+ Year Member



Thanks.