We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,473 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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?

3
Contributors
3
Replies
21 Hours
Discussion Span
5 Months Ago
Last Updated
5
Views
Dani
The Queen of DaniWeb
Administrator
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
Administrator
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

Well, in all honesty I thought you had been banging your head on the keyboard when I first saw it. :D

After seeing this and thinking about it, this is fascinating methodology, and I've begun studying it.

This subject is still way above me so I can't make a conclusive comment here, but I did find this regular expression tester. At the moment I can't see how it works, and it may not be advanced enough for what you are looking for.

BigPaw
Posting Pro
569 posts since Oct 2012
Reputation Points: 17
Solved Threads: 25
Skill Endorsements: 2

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1016 seconds using 2.8MB