diff options
author | Florian Pritz <bluewind@xinu.at> | 2011-10-03 22:04:20 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2011-10-03 22:04:20 +0200 |
commit | 0526102864aaad148711715ad4e7d22c1de89263 (patch) | |
tree | 11d9897089ac9e3f5f4f41e8f6944d13de161d0b /regcheck.pl | |
parent | dc0ae2b4a8d4322a2f3c6f8985ca365698cf556e (diff) | |
download | bin-0526102864aaad148711715ad4e7d22c1de89263.tar.gz bin-0526102864aaad148711715ad4e7d22c1de89263.tar.xz |
regcheck.pl: rework to print only matches
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'regcheck.pl')
-rwxr-xr-x | regcheck.pl | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/regcheck.pl b/regcheck.pl index c5a7023..c5b5f89 100755 --- a/regcheck.pl +++ b/regcheck.pl @@ -3,18 +3,25 @@ use warnings; use strict; use File::Basename; -if (@ARGV != 2) { +if (@ARGV < 2) { print "usage: ", basename($0), " <regexp> <string>\n"; exit 2; } -my $string = $ARGV[1]; -my $pattern = $ARGV[0]; +my $pattern = shift; -if ($string =~ /$pattern/) { - print "\e[0;32mmatches:\e[0m $&\n"; - exit 0; -} else { - print "\e[0;31mno match\e[0m\n"; - exit 1; +for my $string (@ARGV) { + if (my @matches = $string =~ /$pattern/) { + print "\e[0;32mmatches:\e[0m "; + if ($#- != 0) { + for my $match (@matches) { + print $match; + } + } else { + print "$&"; + } + print "\n"; + } else { + print "\e[0;31mno match\e[0m\n"; + } } |