summaryrefslogtreecommitdiffstats
path: root/regcheck.pl
blob: c5b5f89d47d2c4de3079686abd047d0612976fbd (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
#!/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) {
			for my $match (@matches) {
				print $match;
			}
		} else {
			print "$&";
		}
		print "\n";
	} else {
		print "\e[0;31mno match\e[0m\n";
	}
}