travisowens Posted March 22, 2004 Posted March 22, 2004 Why is the following true when txtInput.Text is ""? Regex.IsMatch("foobar", txtInput.Text) And how do I stop this? Quote Experience is something you don't get until just after the moment you needed it
Leaders Iceplug Posted March 22, 2004 Leaders Posted March 22, 2004 Probably because there are (hypothetically) strings of zero length inside of your string there. If "oba" is in your string, why wouldn't "ba" be in your string, why wouldn't "a" be in your string, and why wouldn't "" be in your string? I would suggest doing something like this: (Regex.IsMatch("foobar", txtInput.Text) && txtInput.Text.Length > 0) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
travisowens Posted March 22, 2004 Author Posted March 22, 2004 Yea, it was pretty obvious to me that .Net sees "" as part of a value. I have no idea why .Text.Length > 0 didn't cross my mind, such an easy quick fix. Is it me or does this seem like a real bizarre thing for RegEx because I don't recall Perl or PHP (ugh, PHP regex!) ever behaving like this. Quote Experience is something you don't get until just after the moment you needed it
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.