Skip to content

Commit

Permalink
Don't make the main regex in the --and list a lookahead
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Dec 20, 2024
1 parent bc19134 commit 0b8e85b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/App/Ack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -846,14 +846,19 @@ sub build_all_regexes {
my @match_parts;
my @hilite_parts;

for my $part ( $opt_regex, @parts ) {
my ($match, $scan) = build_regex( $part, $opt );
for my $part ( @parts ) {
my ($match, undef) = build_regex( $part, $opt );
push @match_parts, "(?=.*$match)";
push @hilite_parts, $match;
$re_scan //= $scan;
}
$re_match = join( '', @match_parts ); # All required, not optional.

my ($match, $scan) = build_regex( $opt_regex, $opt );
push @match_parts, ".*$match";
push @hilite_parts, $match;

$re_match = join( '', @match_parts );
$re_hilite = join( '|', @hilite_parts );
$re_scan = $scan;
}
# OR: alpha OR beta
elsif ( @parts = @{$opt->{or}} ) {
Expand All @@ -866,9 +871,9 @@ sub build_all_regexes {
push @scan_parts, $scan;
}

$re_match = join( '|', @match_parts );
$re_match = join( '|', @match_parts );
$re_hilite = $re_match;
$re_scan = join( '|', @scan_parts );
$re_scan = join( '|', @scan_parts );
}
# NOT: alpha NOT beta
elsif ( @parts = @{$opt->{not}} ) {
Expand Down

0 comments on commit 0b8e85b

Please sign in to comment.