in reply to Test RegEx Validity

Use eval to catch the fault:
eval { "" =~ /$re/; $bool = 1 };

Replies are listed 'Best First'.
Re^2: Test RegEx Validity
by Fletch (Bishop) on Nov 28, 2004 at 01:28 UTC

    There's no need to actually use it in the eval, and you can save off the result and use it after the check.

    sub validate_re { my $re = shift; eval { $re = qr/$re/ }; return $@ ? undef : $re }

    That will return either an already compiled regexp or undef (and $@ will indicate what was wrong in that case).