beyondgrep / ack3

ack is a grep-like search tool optimized for source code.
https://beyondgrep.com/
Other
712 stars 66 forks source link

Allow searching for multiple regexes #110

Open hoelzro opened 6 years ago

hoelzro commented 6 years ago

For example, something like ack -m one -m two would match all lines that contain "one" or "two"

Prior work exists in git grep in the form of --and, --or, and --not

n1vux commented 6 years ago

On Dec 1, 2017 2:59 PM, "Rob Hoelz" notifications@github.com wrote:

For example, something like ack -m one -m two would match all lines that contain "one" or "two"

Prior work exists in git grep in the form of --and, --or, and --not

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/beyondgrep/ack3/issues/110, or mute the thread https://github.com/notifications/unsubscribe-auth/AANS-KlCFTUe6wk-8vHAfhxYqKcYdS2lks5s8FqWgaJpZM4Qy1ui .

We already have Cookbook section on emulating this within a single Perl RE (but doesn't scale beyond two well).

(Having explicit syntactic sugar could be a good thing. Just saying we have equivalent strength just not equivalent syntax.)

flwyd commented 3 years ago

Rather than using --or for this, I recommend allowing --match to be specified multiple times. This aligns with the behavior of grep and ripgrep (-e is multi-instance). The current behavior is that the final --match on the command line silently overrides the other ones.

I also think it makes sense to do this independent of the --and proposal in #172. The semantics of specifying --match multiple times should be clearer than Boolean-looking flags.

Aside: I went looking for the cookbook to see the recommended way of faking this (I'm assuming it's something like "join all the patterns with |"), but I could not find any such cookbook in the man page, on the website, or with a Google search.

n1vux commented 3 years ago

Cookbook - not everything we've thought of for Cookbook has been posted. The Cookbook issue ticket has lots more ideas.

Yes, combining patterns with | gets you OR easily and highlights correctly.
AND is harder cookbook-style, tho it is possible (and highlighting is a mess aka wrong). Which is why AND would be the natural semantics for multiple --match clauses if ever supported without explicit --or/--and .

petdance commented 2 years ago

See also #172