I am asking about is that:
I want to save Regex rules in a file
and from the script(perl script) I want to match URL content with the rules in the file:S
Note:the file doesn’t content normal words, it content Regex rules
and i want to match the URL with each regex rule saved in the file
it’s like htaccess idea? is that possible?
Perl – Regular expressions?
April 21, 2010 By













example below:
edit: regexes in the file don’t have the delimiters (i.e. ^foo and not /^foo/)
#!/usr/bin/perl
#
use strict;
if (scalar(@ARGV) < 1) {
print STDERR "Usage: $0 URL [URL] \n";
exit(1);
}
my $fh;
open($fh, "<rules") or die "$!";
my @rules = <$fh>;
foreach my $url (@ARGV) {
$url =~ s#^http://##;
$url =~ s#^https://##;
foreach my $rule (@rules) {
chomp $rule;
if ($url =~ m/$rule/) {
print "match for $rule for $url\n";
}
}
}
close($fh);