Home: Perl Programming Help: Regular Expressions:
Valid Regular expression



anilm
stranger

Jun 29, 2001, 7:14 AM


Views: 12382
Valid Regular expression

Dear friends!
how do i find out the validity of a regular expression pattern, with out passing any string. (I mean are the characters, special characters etc.. used in the pattern are proper.)

regards
anilm



mhx
Enthusiast

Jun 29, 2001, 7:54 AM


Views: 12381
Re: Valid Regular expression

Hi,

say your regex is stored in $re, then you can test if it's valid with

Code
eval { '' =~ /$re/ }; 
unless( $@ ) {
print "Regex is valid!\n";
}
else {
print "Regex is invalid!$@";
}

Hope this is what you were looking for.

-- Marcus

(This post was edited by mhx on Jun 29, 2001, 6:59 AM)