in reply to Set theory in regexs
If you wanted to specify a list of foo's to match against, such as only d4 or b2, you could try this instead . . .use strict; my $string = 'bar a2 b2 c3 d3 d4 a1 f2 f3'; my $flag = 0; foreach(split(/\s+/, $string)) { $flag++, last if /\w\d/; } print "foo's found in list\n" if $flag;
Hope this helps, Jeffuse strict; my @foos = qw(d4 b2); my $string = 'bar a2 b2 c3 d3 d4 a1 f2 f3'; my $flag = 0; foreach my $cand (split(/\s+/, $string)) { foreach(@foos) { $flag++, last if $cand =~ /$_/; } } print "foo's found in list\n" if $flag;
UPDATE: Oops, you wanted d4 AND b2 - luckily for me, merlyn has got you covered . . .
|
|---|