tags:

views:

134

answers:

2

I want to match this url /Real_estate_Listing_Detail.asp?PropID=245 with the ability to EXCEPT PropID numbers...

In other words,

Match /Real_estate_Listing_Detail.asp?PropID=ANY NUMBER HERE, except, 286,289,290,180

Thanks in advance... this shouldnt be as hard as I make it...

This is for a wordpress plugin, so a single line experssion is needed.

+2  A: 

If the language you are using supports look-around assertions, you could use this:

^/Real_estate_Listing_Detail\.asp\?PropID=(?!(?:286|289|290|180)$)\d+$
^/Real_estate_Listing_Detail\.asp\?PropID=\d+(?<!=(?:286|289|290|180))$

The first is a look-ahead assertion and the second a look-behind assertion.

Otherwise use two expressions: one to match the pattern and one to exclude the specific values:

^/Real_estate_Listing_Detail\.asp\?PropID=\d+$
^/Real_estate_Listing_Detail\.asp\?PropID=(286|289|290|180)$

So the first expression must match while the second must not match.

Gumbo
In the first case, that would fail to match "...PropID=3180" or "...PropID=51289" etc.
David Zaslavsky
Thanks, David. Fixed it.
Gumbo
The problem is I am using a wordpress plugin and can only use single line expressions... any help?
PCRE (used by PHP) supports look-around assertions. So you can use one of the former regular expressions.
Gumbo
A: 

If you're using .NET, you might want to create an instance of System.Uri first to help ensure you've got a real/valid URL. You can then use properties/methods to extract various pieces of the URL to further process as others have described.

Dan