Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uwm.edu!ogicse!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: Perl code to test for valid reg-exp? Message-ID: <1991May2.190148.22749@iwarp.intel.com> Date: 2 May 91 19:01:48 GMT References: <9105021740.AA06244@peanut.crl.dec.com> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 15 In-Reply-To: jmiller@crl.dec.com In article <9105021740.AA06244@peanut.crl.dec.com>, jmiller@crl writes: | Has anyone got a short (preferably) piece of Perl code to test a | string to see whether or not it is a valid regular expression for use | in Perl? I've written a program that allows users to type a string | and then uses that to match against a data base; unfortunately the | program blows up if the user types in an invalid string! Do it inside an eval, and test $@ to see if it compiled properly. eval 'Just_another_Perl_hacker,'; $_ = $@; s/.*"(.*)".*/$1/; s/_/ /g; print -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/