regular expression

T

Tony Johansson

Hi!

Here I have two simple regular expression.
The first one give true which according to me is correct.
The second one also give true but it should give false according to me
because
I say that a match should exist if you have zero o like tn as in the first
example.but
here I have one o.

So why does it not work as expected to have 0 in min range

status = Regex.IsMatch("tn", "to{0,}n");
status = Regex.IsMatch("ton", "to{0,}n");

//Tony
 
J

Jackie

Hi!

Here I have two simple regular expression.
The first one give true which according to me is correct.
The second one also give true but it should give false according to me
because
I say that a match should exist if you have zero o like tn as in the first
example.but
here I have one o.

So why does it not work as expected to have 0 in min range

status = Regex.IsMatch("tn", "to{0,}n");
status = Regex.IsMatch("ton", "to{0,}n");

//Tony

"o{0,}" would mean zero or more of "o". Same as "o*?"
It matches because there are more than zero.
 
P

Peter Duniho

Tony said:
Hi!

Here I have two simple regular expression.
The first one give true which according to me is correct.
The second one also give true but it should give false according to me
because
I say that a match should exist if you have zero o like tn as in the first
example.but
here I have one o.

So why does it not work as expected to have 0 in min range

status = Regex.IsMatch("tn", "to{0,}n");
status = Regex.IsMatch("ton", "to{0,}n");

Try reading this:
http://msdn.microsoft.com/en-us/library/az24scfc.aspx#quantifiers

The quantifier "{0,}" means _at least_ zero 'o' characters. Which you
have in both strings.

You might want to keep that web page handy. It's chock full of useful
information about regex.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top