in reply to One or more of a pattern...

while(<DATA>) { print /^([-\w' ]+\(\d+\)(:[-\w' ]+\(\d+\))*)$/ ? "match capture >$ +1< $_\n" : "no match $_\n"; } __DATA__ namexx(10) name2(8):name3(3) name4(12):name5(3):name6(3) O'Keefe(1) Jo-Anne Smith(2) F$%^Y@^(1) name(1)name(3) name(1)::name(3)

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: One or more of a pattern...
by samtregar (Abbot) on May 11, 2002 at 05:10 UTC
    Don't use ^ and $ when you mean \A and \z!

    -sam

      In this case, where the string the pattern is being run against was obtained from a while (<FILE>) (and should, therefore, be a single line), how do they differ and why do you prefer \A/\z?
        The post was in response to a question about matching against a string. I assumed the poster would just take the regex and stick it into his code unaltered. In that case ^ and $ are clearly wrong since the could allow a bad string like "foo(10):bar(20)\n!!!!!!!!!!" to match. By contrast \A can only mean the start of the string and \z can only mean the end of the string. They are unambiguous and do not depend on options to determine their match.

        Does that answer your question?

        -sam