[SATLUG] Regexp help

Jon Mark Allen jm at allensonthe.net
Mon Sep 15 22:06:48 CDT 2008

> Working on mod rewrite regexp and I'm at a road block.
> My url's look like this: www.website.com/2/index.php?artist=billy%20bob
> With rewrite they now look like this: www.website.com/2/artist/billy_bob
> But last minute I decided I want them to look like this:
> www.website.com/2/artist/billy-bob
> I can't change my mod rewrite rule to exclude the "_" because the URLs have
> already been embedded in my enhanced podcast.
> My actual regexp:
> Options +FollowSymLinks
> RewriteEngine on
> RewriteRule ^2/artist/([A-Za-z0-9._]*[A-Za-z0-9-._]*)$
> /2/index.php?artist=$1 [NC]
> I'm not sure where to stick the "-" to make it work. I've tried before the
> "." and after the "_" without success.
> Thanks for your help.
> ::twistedPickles:: :

If I remember correctly, since you're inside the square brackets, the
'-' will need to be escaped.  Otherwise, it serves as a 'range'
operator, which is why A-Za-z works to include all the letters.  Putting
a backslash ( \ ) in front of the hyphen should make it work.


More information about the SATLUG mailing list