Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] check the correctness of a regular expression

Expand Messages
  • merlyn@stonehenge.com
    ... Piyush Hi, Piyush How can I check the correctness of a regular expression. I have a perl Piyush file that specifies the resource requirements of
    Message 1 of 2 , Mar 23, 2005
    • 0 Attachment
      >>>>> "Piyush" == Piyush Swami <piyush@...> writes:

      Piyush> Hi,

      Piyush> How can I check the correctness of a regular expression. I have a perl
      Piyush> file that specifies the resource requirements of different jobs. Job
      Piyush> name is specified by a regular expression. I want to check, whether the
      Piyush> regex used to specify the jobname is correct or not.
      Piyush> I am trying to eval the file but the program is craching if eval fails.
      Piyush> I want to check it before invoking eval.

      chomp(my $regex = <STDIN>); # random regex from user
      my $is_valid = eval { qr/$regex/; 1 };

      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    Your message has been successfully submitted and would be delivered to recipients shortly.