use warnings;
use strict;
while (<DATA>) {
if (/^[a-z]+\s+\d{2}$/i) {
print "PASS $_";
}
else {
print "FAIL $_";
}
}
__DATA__
xyz 12 45
xyz 123
xyz 12
outputs:
FAIL xyz 12 45
FAIL xyz 123
PASS xyz 12
| [reply] [d/l] [select] |
Thanks toolic :)
That works. I guess using boundary made the difference!
| [reply] |
toolic's solution is the right answer for the few examples you gave, but since you haven't said anything about the larger context of strings you might be getting as input, how should the following be treated by your intended regex?
(foo 12)
foo 12 bar
foo 12, bar 34
Foour score and 12 years ago there were 34 bars in this town.
All the above would fail, given toolic's very tight use of anchors (^ and $). If that's what you want, then the problem is solved. | [reply] [d/l] |