Regex for .htaccess file
I've been really struggling with regex lately ... I never quite got the hang of it. I'm currently hung up on trying to match on the following in my .htaccess file:
^foo/([A-Za-z0-9]+)/([0-9]+)$
The catch is that I want the alphanumeric string to NOT be one of a short list of words i.e. (bar|baz|bat)
How can I match on any alphanumeric word as long as it is not in a list?
Related Article: .htaccess file not working
is a solved Linux and Unix discussion thread by opposition that has 4 replies, was last updated 10 months ago and has been tagged with the keywords: apache.
Dani
The Queen of DaniWeb
21,367 posts since Feb 2002
Reputation Points: 1,555
Solved Threads: 368
Skill Endorsements: 122
I did some more investigating and was able to get it to work (I think) with lookahead??
^foo/((?!\b(bar|baz|bat)\b).)*/([0-9]+)$
It seems to work but can someone confirm that I did it correctly??
Dani
The Queen of DaniWeb
21,367 posts since Feb 2002
Reputation Points: 1,555
Solved Threads: 368
Skill Endorsements: 122
On my phone ATM so can't test it out or anything. But in principle, it looks OK to me. Might be worth getting another opinion though. I'm a little rusty with regex's myself! :)
JasonHippy
Practically a Posting Shark
862 posts since Jan 2009
Reputation Points: 615
Solved Threads: 146
Skill Endorsements: 5