summaryrefslogtreecommitdiffstats
path: root/regcheck.pl
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-01-21 01:18:45 +0100
committerFlorian Pritz <bluewind@xinu.at>2015-01-21 01:18:45 +0100
commit7ffcfbbfc93f1ee5e23945e6a30110f7aaf8ee47 (patch)
treea3d4073d834806cd7bf75a760b446c1e2d5b6764 /regcheck.pl
parent2c6aeeb79dbc5e30aba74a3ed115c794e328ed83 (diff)
downloadbin-7ffcfbbfc93f1ee5e23945e6a30110f7aaf8ee47.tar.gz
bin-7ffcfbbfc93f1ee5e23945e6a30110f7aaf8ee47.tar.xz
regcheck.pl: support multiline files, extend output
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'regcheck.pl')
-rwxr-xr-xregcheck.pl28
1 files changed, 18 insertions, 10 deletions
diff --git a/regcheck.pl b/regcheck.pl
index a89b562..aa7929c 100755
--- a/regcheck.pl
+++ b/regcheck.pl
@@ -3,26 +3,34 @@ use warnings;
use strict;
use File::Basename;
-if (@ARGV < 2) {
- print "usage: ", basename($0), " <regexp> <string>\n";
+if (@ARGV < 1) {
+ print "usage: cat | ", basename($0), " <regexp>\n";
exit 2;
}
my $pattern = shift;
-for my $string (@ARGV) {
- if (my @matches = $string =~ /$pattern/) {
- print "\e[0;32mmatches:\e[0m ";
+my $line_counter = 0;
+while (<>) {
+ $line_counter++;
+ my $line = $_;
+ chomp($line);
+
+ if (my @matches = $line =~ /$pattern/) {
if ($#- != 0) {
- print "\n";
my $counter = 0;
- for my $match (@matches) {
- print $counter++.": \"".$match."\"\n";
+ if (scalar(@matches) == 1) {
+ printf "\e[0;32mmatched group\e[0m \e[0;38;5;12m%s\e[0m in line %d (%s)\n", $matches[0], $line_counter, $line;
+ } else {
+ printf "\e[0;32mmatched %d groups\e[0m in line %d (%s):\n", scalar(@matches), $line_counter, $line;
+ for my $match (@matches) {
+ print "\t".$counter++.": \e[0;38;5;12m".$match."\e[0m\n";
+ }
}
} else {
- print "$&\n";
+ printf "\e[0;32mmatched\e[0m \e[0;38;5;12m%s\e[0m in line %d (%s)\n", $&, $line_counter, $line;
}
} else {
- print "\e[0;31mno match\e[0m\n";
+ #print "\e[0;31mno match\e[0m\n";
}
}