C# Regex.IsMatch returns true when it shouldn't?

Posted by James Cadd on Stack Overflow See other posts from Stack Overflow or by James Cadd
Published on 2011-01-09T22:32:32Z Indexed on 2011/01/09 22:53 UTC
Read the original article Hit count: 919

Filed under:
|
|
|

I'm attempting to match a string that can contain any number of numeric characters or a decimal point using the following regex:

([0-9.])*

Here's some C# code to test the regex:

Regex regex = new Regex("([0-9.])*");

if (!regex.IsMatch("a"))
    throw new Exception("No match.");

I expect the exception to be thrown here but it isn't - am I using the Regex incorrectly or is there an error in the pattern?

EDIT: I'd also like to match a blank string.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET