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
From:
Father Chrysostomos via RT
Date:
July 31, 2013 15:57
Subject:
[perl #119095] Empty regular expression does not match in some cases
Message ID:
rt-3.6.HEAD-2552-1375286244-1166.119095-15-0@perl.org
On Wed Jul 31 08:34:08 2013, zefram@fysh.org 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
https://rt.perl.org:443/rt3/Ticket/Display.html?id=119095

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About