The function of my program is to evaluate user provided patterns
/Bill Clinton/i is NOT a regex pattern. It's a match operator. If you want to execute arbitrary Perl code such as the match operator, you need eval EXPR (and all the attendant validation and security problems) or parse the input yourself (which could be done simply enough in this case).
If you wish to continue use qr//, you'll need to pass an actual regex pattern such as (?i:Bill Clinton)
By the way, I'd avoid using $& since simply using it can negatively affect distant parts of your program. You could change
toif($text =~ $pattern){ print $&; #prints entire match
but I'd avoid globals entirely and useif($text =~ /($pattern)/){ print $1; #prints entire match
if(my ($match) = $text =~ /($pattern)/){ print $match; #prints entire match
In reply to Re: qr// and user provided regex patterns...
by ikegami
in thread qr// and user provided regex patterns...
by misterMatt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |