in reply to Re: qr// and user provided regex patterns...
in thread qr// and user provided regex patterns...
It works, as long as what the user provides doesn't have any spaces in it. (ex: /Bill Clinton/i causes the program to fail, but /BillClinton/i doesn't.) How do I fix that?if($options{c}){ #variable grab my $pattern = eval "qr$options{c}" or die $@; print "Please enter the text you wish to run the pattern on: "; my $text = <STDIN>; chomp $text; if($text =~ $pattern){ print $&; #prints entire match print " " . $text; } else{ print "$pattern on $text Failed. "; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: qr// and user provided regex patterns...
by ikegami (Patriarch) on Jul 30, 2009 at 07:10 UTC | |
by misterMatt (Novice) on Jul 30, 2009 at 07:26 UTC |