Regex Help

Topics: User Forum
Apr 1, 2008 at 1:49 AM
Ok, I've got many rules working just great. The filtering is very powerful, but I can often easily get lost in the cryptic regular expression matching.

I've got a rule setup to rewrite
/Artists/999/Artist-Name TO: /Artists/Artist.aspx?id=999&a=Artist-Name

The rules are set as follows:
RewriteRule ^/artists/(\d+){1}/((?>([^?/\n]|/[^.?/\n])+)(?<!\.aspx))(/?)$ /artists/artist.aspx?artistid=$1&a=$2

This works great. However, I need to extend it now to work with a different page set after the Artist-Name. I would like it to work with the following examples:
/Artists/999/Artist-Name/ShowsTO: /Artists/Shows.aspx?id=999&a=Artist-Name
/Artists/999/Artist-Name/ArticlesTO: /Artists/Articles.aspx?id=999&a=Artist-Name

I'm having trouble with this. I would like to only capture certain words/pages on the last group. Not just any word character, but something like
(shows|articles|fans|store) etc...

I've been messing with this for quite a while now so I would hope to get some pointers... Help!
Apr 1, 2008 at 3:37 AM
First I'd download Expresso - a freeware regex builder/tester - it's helped me immensely!

Remember that any capture group is accessed as $1 or $2, etc... you know that.

So for changing your processing page name, just use the proper $ reference.

RewriteRule ^/artists/(\d+)/(\w+)/(shows|articles|fans|store)$ /artists/$3.aspx?artistid=$1&a=$2

Best of luck...
Apr 11, 2008 at 8:51 PM
Great! Thanks for your help. I have been using a different RegEx tester software RAD Software Regular Expression Designer, but Expresso is MUCH better, thank you!
I've got it working with the help of Expresso...