chomp $user_input; my $regex = eval { qr{$user_input} }; my $error = $@; unless (defined $regex) { print "Your regex seems to be invalid. Try `perldoc perlretut` for +an explanation of valid regexes.\n" print "Regex compilation error was: $error"; }
Update: unconfused variable names, as pointed out by choroba++ and ReturnOfThelonious++
In reply to Re: Making sure user input is a valid regexp
by moritz
in thread Making sure user input is a valid regexp
by gri6507
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |