R
RedGrittyBrick
I need to match fixed string FOO with an optional : terminated prefix
This doesn't work because the RE matches notFOO
for my $x (qw(FOO xxx:FOO yyy.FOO BAR notFOO FOOM)) {
if ($x =~ /^[^:]*:?FOO$/) {
print "Matched $x\n";
} else {
print "- $x\n";
}
}
Actual output:
Matched FOO
Matched xxx:FOO
Matched yyy.FOO
- BAR
Matched notFOO
- FOOM
Desired output:
Matched FOO
Matched xxx:FOO
Matched yyy.FOO
- BAR
- notFOO
- FOOM
xxx and yyy are just examples of \w+ excluding ':'
I've glanced at perlretut but would appreciate a clue.
This doesn't work because the RE matches notFOO
for my $x (qw(FOO xxx:FOO yyy.FOO BAR notFOO FOOM)) {
if ($x =~ /^[^:]*:?FOO$/) {
print "Matched $x\n";
} else {
print "- $x\n";
}
}
Actual output:
Matched FOO
Matched xxx:FOO
Matched yyy.FOO
- BAR
Matched notFOO
- FOOM
Desired output:
Matched FOO
Matched xxx:FOO
Matched yyy.FOO
- BAR
- notFOO
- FOOM
xxx and yyy are just examples of \w+ excluding ':'
I've glanced at perlretut but would appreciate a clue.