According to the tutorial I'm following:

{n}        matches exactly n of the previous thing

Thus I expect:

            "fo" =~ /o{2}/ = false
            "foo" =~ /o{2}/ = true
            "fooo" =~ /o{2}/ = false

Instead I get:

            "fo" =~ /o{2}/ = false
            "foo" =~ /o{2}/ = true
            "fooo" =~ /o{2}/ = true

I have similar issues with {x,y}. I expect:

"fa" =~ /a{2,4}/ = false
"faa" =~ /a{2,4}/ = true
"faaa" =~ /a{2,4}/ = true
"faaaa" =~ /a{2,4}/ = true
"faaaaa" =~ /a{2,4}/ = false

Instead I get:

"fa" =~ /a{2,4}/ = false
"faa" =~ /a{2,4}/ = true
"faaa" =~ /a{2,4}/ = true
"faaaa" =~ /a{2,4}/ = true
"faaaaa" =~ /a{2,4}/ = true

What am I doing wrong, or misunderstanding?

Daniel Kurtz

Answer 1)
A regular expression need not match the entire string. It is sufficient if a
PART of the string matchesdthe reg-ex (unless specified otherwise).
/o{2}/ matches exactly "oo" in "fooo". The regex matching algorithm is
satisfied with this, and doesnt care about the other parts of the string.

Answr 2)
a{2,4} requires a minimum of two 'a's and a max of  4 'a's. The first case
should not be a problem. The second case is ALSO satisfied if we leave out
the last 'a'.

This makes much more sense if you try to match "faaaaa" and "faaaab" and
"faaab" afainst /a{2,4}b/






It is Virus free mail . (IIFT)


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to