From: Willem van Rumpt on
Tony Johansson wrote:

>
> As you say The purpose of three is "find me a sequence of 'o' characters,
> at least
> 1, and at most three long"
>
> So can I say that the expression means find at least one 'o' at most three
> 'o' anywhere in the string.
> It could be at the very beginning in the middle or at the very end what the
> other character are doesn't matter.
>
> //Tony
>

Correct.
Also note that it tries to match as much as it can, thus returning 3
matches in "foooooood" (7 'o's), instead of 7 matches.

--
Willem van Rumpt
From: Jeff Johnson on
"Willem van Rumpt" <nothing(a)nowhere.com> wrote in message
news:%23JL6dOC%23KHA.4840(a)TK2MSFTNGP04.phx.gbl...

>> As you say The purpose of three is "find me a sequence of 'o'
>> characters, at least
>> 1, and at most three long"
>>
>> So can I say that the expression means find at least one 'o' at most
>> three 'o' anywhere in the string.
>> It could be at the very beginning in the middle or at the very end what
>> the other character are doesn't matter.
>>
>> //Tony
>
> Correct.
> Also note that it tries to match as much as it can, thus returning 3
> matches in "foooooood" (7 'o's), instead of 7 matches.

For completeness, this behavior can be altered by adding "?" after the
qualifier to make it lazy:

{1,3}?

Then there would have been seven matches of single o's.


From: Harlan Messinger on
Tony Johansson wrote:
> "Willem van Rumpt" <nothing(a)nowhere.com> skrev i meddelandet
> news:e$Bg2MA%23KHA.5464(a)TK2MSFTNGP05.phx.gbl...
>> Tony Johansson wrote:
>>> Hi!
>>>
>>> Here I say minimum 1 o and maximum three o but here I have more then
>>> three o and this expression give true but
>>> it should give false according to me ?
>>>
>>> bool status = Regex.IsMatch("foooooood", "o{1,3}");
>>>
>>> //Tony
>> Because your criteria has multiple matches:
>>
>> f[ooo][ooo][o]d
>>
>>
>> --
>> Willem van Rumpt
>
> But according to me means "o{1,3}" that I must have at least 1 o and maximum
> of three o.

It means that your string must have a sequence of between 1 and 3 o's.
Even a string of 500 o's *includes a sequence of between 1 and 3 o's*.
The pattern "o{1,3}" means "match 1 through 3 o's", not "match 1 through
3 o's unless they are followed by another o".

> I meam what is the purpose of using a max of 3 here then ?

In your example it doesn't serve any purpose. It serves a purpose if
it's followed by something. If your pattern had been "o{1,3}d", then it
would match "fod", "food", and "foood" but not "fooooooood".

From: Harlan Messinger on
Harlan Messinger wrote:
> Tony Johansson wrote:
>> "Willem van Rumpt" <nothing(a)nowhere.com> skrev i meddelandet
>> news:e$Bg2MA%23KHA.5464(a)TK2MSFTNGP05.phx.gbl...
>>> Tony Johansson wrote:
>>>> Hi!
>>>>
>>>> Here I say minimum 1 o and maximum three o but here I have more then
>>>> three o and this expression give true but
>>>> it should give false according to me ?
>>>>
>>>> bool status = Regex.IsMatch("foooooood", "o{1,3}");
>>>>
>>>> //Tony
>>> Because your criteria has multiple matches:
>>>
>>> f[ooo][ooo][o]d
>>>
>>>
>>> --
>>> Willem van Rumpt
>>
>> But according to me means "o{1,3}" that I must have at least 1 o and
>> maximum of three o.
>
> It means that your string must have a sequence of between 1 and 3 o's.
> Even a string of 500 o's *includes a sequence of between 1 and 3 o's*.
> The pattern "o{1,3}" means "match 1 through 3 o's", not "match 1 through
> 3 o's unless they are followed by another o".
>
>> I meam what is the purpose of using a max of 3 here then ?
>
> In your example it doesn't serve any purpose. It serves a purpose if
> it's followed by something. If your pattern had been "o{1,3}d", then it
> would match "fod", "food", and "foood" but not "fooooooood".
>
Forget what I just said. It wouldn't make any difference there either.
For the maximum value to make a difference, there has to be something
else both before AND after the quantified item in the pattern. Pretend
I'd written "fo{1,3}d".
From: Jeff Johnson on
"Harlan Messinger" <hmessinger.removethis(a)comcast.net> wrote in message
news:85l2goFg86U1(a)mid.individual.net...

>>> I meam what is the purpose of using a max of 3 here then ?
>>
>> In your example it doesn't serve any purpose. It serves a purpose if it's
>> followed by something. If your pattern had been "o{1,3}d", then it would
>> match "fod", "food", and "foood" but not "fooooooood".
>>
> Forget what I just said. It wouldn't make any difference there either. For
> the maximum value to make a difference, there has to be something else
> both before AND after the quantified item in the pattern. Pretend I'd
> written "fo{1,3}d".

It does make a difference, and in certain circumstances (no examples come
immediately to mind) you might want it: This pattern creates multiple
matches with each match being at most three o's.