RegularExpressionValidator
Hi there.
I want to allow the user to select any but a couple of items in a listbox. I've got a RegularExpressionValidator for the listbox but I'm somewhat stuck on the regular expression - how do I say NOT string a or b?
"^(a|b)$" is exactly wrong but I don't seem to be able to say NOT "^(a|b)$" ... any clues???
Thanks for your time,
T
Re: RegularExpressionValidator
If you need to match any one-character string , except "A" AND "B", try
If you need to match any string not containing the letters 'A' or 'B', try
Or if you need to match any string not beginning with the letter 'A' or 'B':
- petter
Re: RegularExpressionValidator
Thanks for the reply. I'm trying to match a string, rather than character set - for example NOT ("Apples" OR "Pears"):
NOT (and that's the bit I'm having trouble with) "^(Apples|Pears)$".
Thanks again,
T
Re: RegularExpressionValidator
Ok, then you can use negative lookahead.
To match a string, except "Apples" or "Pears":
Code:
^(?!Apples$|Pears$).*$
Or, to match any string except thoes begginning with "Apples" or "Pears", try:
Code:
^(?!Apples|Pears).*$
- petter
Re: RegularExpressionValidator
That's exactly it - you're brilliant and amazing. I wasn't even on the right track! Regular expressions are indeed a world unto their own...
Thanks again,
T.