I am working on a project which at one point gets a list of files from an ftp server. At that point it either returns an arrayref of files OR if an optional regex reference
You could use YAPE::Regex to parse the regular expression to see if there is a capture present:
use warnings;
use strict;
use YAPE::Regex;
filter_files(qr/foo.*/);
filter_files(qr/(foo).*/);
sub filter_files {
my ($pattern) = @_;
print "$pattern ";
if (has_capture($pattern)) {
print "yes capture\n";
}
else {
print "no capture\n";
}
}
sub has_capture {
my ($pattern) = @_;
my $cap = 0;
my $p = YAPE::Regex->new($pattern);
while ($p->next()) {
if (scalar @{ $p->{CAPTURE} }) {
$cap = 1;
last;
}
}
return $cap;
}
__END__
(?-xism:foo.*) no capture
(?-xism:(foo).*) yes capture