J
Justin C
I have a list of strings, some contain spaces. The strings are used as
patterns for a regex match, they don't seem to be working! I tried
substituting the space with '\s' but I got warnings, and still no match.
I'm sure there's a way to do this, but Google isn't providing any
answers (more likely I don't know how to formulate a useful search).
Anyway, here's what I have:
#!/usr/bin/perl
use warnings;
use strict;
my @list = (
"Fred Flintstone",
"Barney Rubble",
);
while (<DATA>) {
my $string = chomp $_;
foreach (@list) {
if ( $string =~ /($_)/ ) {
print "Matched ", $1, "\n";
}
}
}
__DATA__
A man called Fred Flintstone lives in a cave.
Fred's neighbour is called Barney Rubble.
Fred is married to Wilma Flintstone and Barney Rubble is married to Betty.
Justin.
patterns for a regex match, they don't seem to be working! I tried
substituting the space with '\s' but I got warnings, and still no match.
I'm sure there's a way to do this, but Google isn't providing any
answers (more likely I don't know how to formulate a useful search).
Anyway, here's what I have:
#!/usr/bin/perl
use warnings;
use strict;
my @list = (
"Fred Flintstone",
"Barney Rubble",
);
while (<DATA>) {
my $string = chomp $_;
foreach (@list) {
if ( $string =~ /($_)/ ) {
print "Matched ", $1, "\n";
}
}
}
__DATA__
A man called Fred Flintstone lives in a cave.
Fred's neighbour is called Barney Rubble.
Fred is married to Wilma Flintstone and Barney Rubble is married to Betty.
Justin.