Le Tuesday 11 November 2008 21:47:55 Ian Hilt, vous avez écrit : > On Tue, 11 Nov 2008, Francis Galiegue wrote: > > Le Tuesday 11 November 2008 02:49:19 Tait, vous avez écrit : > > > > > > + if ($c_file =~ /^To:\s*+(.+)\s*\nCc:/ism) { > > > > > > > > > > Greedy operators are only supported with perl 5.10 or more... I > > > > > think it's a bad idea to use them... > > > > > > > > The problem here was that a space should follow the field, but it may > > > > not. The user may unwarily backup over it. "\s*" would match this > > > > case. > > > > > > > > But if there is a space, it is included in the "(.+)". > > > > > > Not in any version of Perl to which I have access. > > > > And if you see a space in (.+), your regex engine is buggy anyway. > > So what does this script produce on your systems? > > > #!/usr/bin/perl -Tw > --8<-- > use strict; > my $ws = "To: \nCc:"; > > $ws =~ /^To:\s*(.+)\s*\nCc:/ism; > > if ($1 eq ' ') { > print "\$1 is equal to a space.\n"; > } > -->8-- > > On mine, it prints the message. So it seems it is matching _a_ space. Which is perfectly normal. The first \s* wanted spaces, it got them. But it left nothing for the capturing .+ behind. And any quantifier (except when it is possessive) _MUST_ backtrack in order for the full regex to complete. This is why the .+ captured the space: the first \s* was perfectly fine with no space at all, and the second, well, didn't find any space but it didn't care either. -- Francis Galiegue ONE2TEAM Ingénieur système Mob : +33 (0) 6 83 87 78 75 Tel : +33 (0) 1 78 94 55 52 fge@xxxxxxxxxxxx 40 avenue Raymond Poincaré 75116 Paris -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html