Reputation: 959
I have a perl script that contains a few regexes in variables, such as this:
my $velar_velar = qr/([a-zA-Z']*(?:[^n\s]g|[^n\s]k))\s+((?:g|k|c[^ieyh])[a-zA-Z']*)/;
Later, I use these in an if
(and elsif
) statements, but I want this regex to be able to match more than once per line:
$text = "tack go pack go";
if ($text =~ /$velar_velar/g) {
print "Yes";
}
Where it would print "Yes" twice. I have tried the code I have here but it doesn't seem to work. I've also tried putting /g
at the end of the regex variable but that does not work either.
How do I get my regex to match more than once when it is a variable? I
Upvotes: 0
Views: 327
Reputation: 898
Change if ($text =~ /$velar_velar/g) {
to while ($text =~ /$velar_velar/g) {
.
Upvotes: 2