summaryrefslogtreecommitdiffstats
path: root/regcheck.pl
blob: a89b562310171b4db4de242d634c3799cb978ca8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl
use warnings;
use strict;
use File::Basename;

if (@ARGV < 2) {
  print "usage: ", basename($0), " <regexp> <string>\n";
  exit 2;
}

my $pattern = shift;

for my $string (@ARGV) {
	if (my @matches = $string =~ /$pattern/) {
		print "\e[0;32mmatches:\e[0m ";
		if ($#- != 0) {
			print "\n";
			my $counter = 0;
			for my $match (@matches) {
				print $counter++.": \"".$match."\"\n";
			}
		} else {
			print "$&\n";
		}
	} else {
		print "\e[0;31mno match\e[0m\n";
	}
}