Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Why is the following true when txtInput.Text is ""?

 

Regex.IsMatch("foobar", txtInput.Text)

 

And how do I stop this?

Experience is something you don't get until just after the moment you needed it
  • Leaders
Posted

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)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

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.

Experience is something you don't get until just after the moment you needed it

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...