develooper Front page | perl.perl5.porters | Postings from July 2013

[perl #119095] Empty regular expression does not match in some cases

Thread Previous | Thread Next
Father Chrysostomos via RT
July 31, 2013 15:57
[perl #119095] Empty regular expression does not match in some cases
Message ID:
On Wed Jul 31 08:34:08 2013, wrote:
> Petr Pisar wrote:
> >Just if you want to know my use case, the second match uses a regular
> >expression specified by an user. And user could assume that an empty
> >expression matches any string.
> To provide consistent semantics to the user, you need to process the
> user-supplied regexp, by something like
> 	$perlre = $userre eq "" ? qr/(?:)/ : qr/$userre/;
> or
> 	$perlre = qr/(?:$userre)/;
> (Compiling the regexp early with qr// is often a good idea.)

Watch out for qr/$userre/.  I fixed that in perl 5.18 (commit
6a97c51d3ccb), but in earlier perls qr// would trigger the same
behaviour.  In 5.18+ qr/$userre/ will work as expected (like /(?:)/)
with empty patterns.


Father Chrysostomos

via perlbug:  queue: perl5 status: resolved

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About