Tommy Jakobsen
Tommy Jakobsen

Reputation: 2361

RegEx, matching if not containing

I've been trying to figure out how to write this regular expression. It is to be used for ISAPI_Rewrite, a module for IIS 6, for doing URL rewriting.

I want the url /hg/<parameter> to be mathed, so it can be rewrited to /hg/hgwebdir.cgi/<parameter>.

I've matched it using ^/hg/(.*).

My problem is, if the URL /hg/hgwebdir.cgi/<parameter> is used, the regex should NOT match. Using the above regex with this URL, will rewrite to /hg/hgwebdig.cgi/hgwebdig.cgi/<parameter> which is not correct.

Can you help me create the matching pattern?

Upvotes: 1

Views: 1581

Answers (1)

Jens
Jens

Reputation: 25563

You could use a negative lookahead to do this:

"^/hg/(?!hgwebdir.cgi)(.*)"

http://www.regular-expressions.info/tutorial.html is a great tutorial for regular expressions. =)

Upvotes: 3

Related Questions