diff options
-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"; + } } |