0

I have definition string from my user to match an input string and i would like to simplify the definition string so my user won't need to know regexp internal.

my thought was to allow */-7721/-7722/-7723 to match any given 4 digit string which is not 7721 AND not 7722 AND not 7723.

I am searching for a regexp to perform the above on an input string which is a 4 digit number.

I have tried using the ?! notation, but it can't mis-match the entire string.

(?![0-9]{4}) - this doesn't allow any 4 digit string.

((?!(7721))(?!(7722))(?!(77223)) - this also didn't work

Is there an AND operator to perform the above?

Thanks,

Toto
  • 89,455
  • 62
  • 89
  • 125
NirMH
  • 4,769
  • 3
  • 44
  • 69
  • In which programming language? Since these are numbers, can you use mathematics, rather than string operations? – johnsyweb Feb 06 '12 at 13:33
  • @Johnsyweb: actually C++ boost regexp. let me update my tags. How can i use maths? (sorry for asking)? – NirMH Feb 06 '12 at 13:34
  • ?= perhaps? http://stackoverflow.com/questions/469913/regular-expressions-is-there-an-and-operator – Tim Feb 06 '12 at 13:34
  • `int i = boost::lexical_cast(s); return i < 10000 && i != 7721 && i != 7722 && i != 7723;` – johnsyweb Feb 06 '12 at 13:47

1 Answers1

1

You forgot ^:

^(?!(?:7721))(?!(?:7722))(?!(?:7723))\d{4}

Edited: added \d{4} for actually matching the string, not just testing

user1096188
  • 1,809
  • 12
  • 11