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

Re: [perl #119095] Empty regular expression does not match in somecases

Thread Previous | Thread Next
From:
Zefram
Date:
July 31, 2013 15:33
Subject:
Re: [perl #119095] Empty regular expression does not match in somecases
Message ID:
20130731153329.GK11327@fysh.org
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.)

-zefram

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