in reply to File::Find find several strings in one directory
You can use grouping with the or operator within the regex, combined with word boundaries:
use warnings; use strict; use feature 'say'; my @strings = ( "Bob said hello\n", "Alice doesn't like Chris\n", "This line won't match\n" ); for (@strings){ say "yay!" if /(?:\bAlice\b|\bBob\b|\bChris\b)/; }
That says:
/ (?: # group, but don't capture \bAlice\b # capture Alice, if it is standalone | # or \bBob\b # same as Alice above | # or \bChris\b # same as Alice and Bob ) # end grouping /
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: File::Find find several strings in one directory
by Staralfur (Novice) on May 09, 2017 at 18:06 UTC |
In Section
Seekers of Perl Wisdom