in reply to ^x* vs x*$
You are exactly correct in your analysis, and correct to be unhappy with what Perl is doing. :-(
The first is a bug in 5.6.0. It doesn't happen in 5.005_03. It likely has been fixed by Hugo already. Anyone who wants to check that can follow my advice in Getting current versions of Perl and see if it is still there with more current patches.
The second likewise looks to me like a bug. It has been around longer though. (It appears in 5.005_03 and 5.6.0.) You match the first time and pos() is set to the end of the string. The second time you go back, start from pos() - and find that you can match at the end of the string. The first time it needs to mark that it actually matched the end of the string and not do so the next time.
At this point you should run "perlbug" with your code, and toss in my observation that the first behaved differently in Perl 5.005_03. But first I would clean it up as follows:
Also Jeffrey Friedl (jfriedl@yahoo-inc.com) is in the process of rewriting his Mastering Regular Expressions book and has been tracking down all of the RE bugs he can. I would toss this at him. He likely will want to check whether equivalents of the second bug appear in other RE tools.&re_test("x", '^x*'); &re_test("x", 'x*$'); sub re_test { my $str = shift; my $re_desc = shift; my $re = qr/$re_desc/; my @matches = ($str =~ /$re/g); my $num_match = @matches; print "Test String\t>$str<\n", "Test Regexp\t>$re_desc<\n", "Prematch\t>$`<\n", "Match\t\t>$&<\n", "Postmatch\t>$'<\n", "Num Matches\t>$NumMatch<\n", "Match Arrary:\n", map {"\t\t>$_<\n"} @matches; print "\n\n"; }
I would do this for you, but I think it is good to encourage people to get involved in the process. :-)
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: Re: ^x* vs x*$
by tye (Sage) on Aug 19, 2000 at 22:02 UTC | |
by tilly (Archbishop) on Aug 20, 2000 at 06:16 UTC | |
Re: ^x* vs x*$
by Abigail-II (Bishop) on Sep 18, 2003 at 15:52 UTC | |
by tilly (Archbishop) on Oct 10, 2004 at 07:00 UTC | |
by Steve_p (Priest) on Nov 16, 2007 at 16:26 UTC | |
by tilly (Archbishop) on Nov 16, 2007 at 17:28 UTC |