Couple of days back I got a query:
What expression will i use in VB validator for the following:
> Allow enter any alpha characters in text box,
> but exclude codes 00 and 50
> Currently my expression looks like \w{1,20}
> How modify to exclude 00 and 50?
I replied with the following solution:
try this:
[^\s?50|\s?00]\w{1,20}
OR
[^\s?50|\s?00]\w*
both works with the following
Example Text: "Ask me 50 00 times"
Matches:
Ask
me
times
Important Note: But the above expression will eliminate 5 0 characters in any order so it will also eliminate 05 as well.
If you do not want that to happen please try the following expression.
\s?\b((?!\b50\b|\b00\b)\w*)\b\s?
and eliminate any other words which has only 50 or 00 in it.
Here is another variation:
If you want to eliminate any word which has the 50 or 00 anywhere in the sentence use the following.
\b((?!\b\w*50\w*\b|\b\w*00\w*\b)\w*)\b\s?
Example Text: “Ask me 50 times 50times times50 00or50times“
Matches:
Ask
me
times
This Regex is also available at RegexLib.com
http://www.regexlib.com/REDetails.aspx?regexp_id=1244