Catch invalid user supplied regexps to grep

Since an invalid regexp (e.g. qr/(?<!.*)/) causes perl to croak,
we now verify that the regexp can be compiled before it's used.