[Javascript] Inverting a regex pattern
Shawn Milo
shawn.milo at gmail.com
Mon May 2 07:35:19 CDT 2005
If I understand properly, are you asking for a way to find out if
something *doesn't* match your regex? If so, just test for a match,
and then you can do something on false.
if (someValue.match(regEx)){
//do this
}else{
//do that
}
OR
if (someValue.match(regEx) == false){
//do this
}
If I'm misunderstanding your question, please elaborate.
Shawn
On 5/1/05, David Lovering <dlovering at gazos.com> wrote:
> Here's another question that I'm sure can be answered quickly, and then I'll
> spend the next month feeling stupid for having asked it --
>
> Is there a quick-and-dirty way of creating a complementary regular
> expression, given another? For example, if somebody gives me
>
> var re = /^\([2-9][0-9]{2}\)\b[2-9][0-9]{2}\-[0-9]{4}$/;
>
> [a rather crude phone number pattern-match], can I do something like
>
> var not_re = /[^(re)]?/; // obviously invalid, for a number of
> very good reasons //
>
> to look for the shortest string which violates the original pattern? If I
> could come up with something like that, my life would be complete and I
> would lack for nothing... [***]
>
> -- Dave Lovering
>
> *** Obviously a corollary of the "simple pleasures for simple minds" adage
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
--
Voicemail any time at:
206-666-MILO
More information about the Javascript
mailing list