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
The flag -e / --regexp allows one to search multiple patterns.
Currently, a search rg -e pattern1 -e pattern2 returns the union of the results that would be returned by the two searches rg -e pattern1 and rg -e pattern2.
The files returned by rg -e pattern1 -e pattern2 are the files that contain at least one of [pattern1, pattern2].
My request is to add a flag (e.g. --conjunction) where files have to contain all the given patterns to be a match.
So the command rg -e pattern1 -e pattern2 --conjunction would return the files that contain both pattern1' and pattern2
Another thing that has to be taken into account here is whether multiline search is performed or not.
If multiline search is performed, the patterns could be allowed to be on different lines, if multiline search is not performed the patterns could be required to all be on the same line.
I currently use this command to iteratively filter the files to get the files where all given patterns are present:
Simply constructing a regex like pattern1 .* pattern2 is not an option here, because the patterns should be allowed to appear in any order.
For two patterns you would have to search for pattern1 .* pattern2 and pattern2 .* pattern1.
For three patterns, there would of course be 6 different orders in which the patterns could appear, etc.
So the flag would not strictly be required in the multiline-search case (as I have demonstrated), but it would be much more elegant.
In the single-line search case however (where you want all patterns in the same line, in any order) such a flag would be required, because the only other way would be to construct a very long and complicated regular expression.
The text was updated successfully, but these errors were encountered:
The flag
-e
/--regexp
allows one to search multiple patterns.Currently, a search
rg -e pattern1 -e pattern2
returns the union of the results that would be returned by the two searchesrg -e pattern1
andrg -e pattern2
.The files returned by
rg -e pattern1 -e pattern2
are the files that contain at least one of [pattern1
,pattern2
].My request is to add a flag (e.g.
--conjunction
) where files have to contain all the given patterns to be a match.So the command
rg -e pattern1 -e pattern2 --conjunction
would return the files that contain bothpattern1'
andpattern2
Another thing that has to be taken into account here is whether multiline search is performed or not.
If multiline search is performed, the patterns could be allowed to be on different lines, if multiline search is not performed the patterns could be required to all be on the same line.
I currently use this command to iteratively filter the files to get the files where all given patterns are present:
Simply constructing a regex like
pattern1 .* pattern2
is not an option here, because the patterns should be allowed to appear in any order.For two patterns you would have to search for
pattern1 .* pattern2
andpattern2 .* pattern1
.For three patterns, there would of course be 6 different orders in which the patterns could appear, etc.
So the flag would not strictly be required in the multiline-search case (as I have demonstrated), but it would be much more elegant.
In the single-line search case however (where you want all patterns in the same line, in any order) such a flag would be required, because the only other way would be to construct a very long and complicated regular expression.
The text was updated successfully, but these errors were encountered: