You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a pattern (with look-around) which with --count reports 2 but with --count-matches reports 0. This doesn't appear to make sense. I would expect ``--count-matchesto report a number at least as high as--count`.
In order to implement --count-matches, we simply re-execute the regex on
the spans reported by the searcher. The spans always correspond to the
lines that participated in the match. This is the correct thing to do,
except when the regex contains look-ahead (or look-behind).
In particular, the look-around permits the regex's match success to
depends on an arbitrary point before or after the lines actually
reported as participating in the match. Since only the matched lines are
reported to the printer, it is possible for subsequent searching on
those lines to fail.
A true fix for this would somehow make the total span available to the
printer. But that seems tricky since it isn't always available. For
PCRE2's case in multiline mode, it is available because we force it to
be so for correctness.
For now, we simply detect this corner case heuristically. If the match
count is zero, then it necessarily means there is some kind of
look-around that isn't matching. So we set the match count to 1. This is
probably incorrect in some cases, although my brain can't quite come up
with a concrete example. Nevertheless, this is strictly better than the
status quo.
Fixes#1573
What version of ripgrep are you using?
How did you install ripgrep?
Choco
What operating system are you using ripgrep on?
Windows 10
Describe your bug.
I have a pattern (with look-around) which with
--count
reports2
but with--count-matches
reports0
. This doesn't appear to make sense. I would expect ``--count-matchesto report a number at least as high as
--count`.What are the steps to reproduce the behavior?
File
test.txt
with contents:Ripgrep usage:
rg --pcre2 -U '(?s)def (\w+);(?=.*use \w+)' test.txt --count-matches
What is the actual behavior?
The output is
0
whereas the output for the same command with--count
instead of--count-matches
is2
.What is the expected behavior?
I would expect an output of
2
and generally the result of--count-matches
to be equal to or greater than that of--count
.The text was updated successfully, but these errors were encountered: