in reply to Re: ?Re: Re: Re: How to identify invalid reg. expr.?
in thread How to identify invalid reg. expr.?
Just use this:
Then use $regex later, safely, as a compiled regex. In fact, wait, it's simpler than that:my $regex = param('foo'); $regex = eval { qr/$regex/ }; if ($@) { "it was bad... handle it" }
since eval will return undef on a failed block, or the compiled Regex object (always true) if it's a valid regex.my $regex = param('foo'); $regex = eval { qr/$regex/ } or do { # handle failure };
-- Randal L. Schwartz, Perl hacker
|
---|