website icon indicating copy to clipboard operation
website copied to clipboard

Add pcre2grep and a category for "does it match across multiple lines?"

Open avar opened this issue 8 years ago • 5 comments

As far as I know no other grep implementation can do this:

$ ./pcre2grep -M 'Copyright(\n|.)*Copying' INSTALL 
   Copyright (C) 1994-1996, 1999-2002, 2004-2016 Free Software
Foundation, Inc.

   Copying and distribution of this file, with or without modification,

avar avatar Jan 08 '18 18:01 avar

What is that doing? Multi-line match?

petdance avatar Jan 08 '18 19:01 petdance

Yes, stand-alone example:

$ (echo foo; echo bar; echo baz) >file ;  ./pcre2grep 'foo.*baz' file; echo $?
1
$ (echo foo; echo bar; echo baz) >file ;  ./pcre2grep -M 'foo.*baz' file; echo $?
1
$ (echo foo; echo bar; echo baz) >file ;  ./pcre2grep -M 'foo(.|\n)*baz' file; echo $?
foo
bar
baz
0

I'm now aware of another grep-like tool that does this.

avar avatar Jan 08 '18 19:01 avar

The silver search does this (by default, nonetheless). ripgrep will also have this soon too.

BurntSushi avatar Aug 07 '18 17:08 BurntSushi

XREF

  • **pcre2grep** is a follow on to the pcregrep , added in #48 ;
  • was mentioned as being Unicode compatible in https://github.com/beyondgrep/ack3/issues/349#issuecomment-1148117205
  • Multi-line capability, adding of to Ack3, is requested in https://github.com/beyondgrep/ack3/issues/171

n1vux avatar Jun 07 '22 03:06 n1vux

As far as I know no other grep implementation can do this:

<pedantic> **paragrep** is already listed on the More Tools page as a multiline grep, that's what it's specifically good for. It wouldn't by default span over the whitespace line paragraph break, but has argument to select a different End of Paragraph RE, so there was at least one already listed. </pedantic>

That said, Multiline/Paragraph modes would be worthy of adding a capability in the comparison table, especially with the list now being at least 4: paragrep pcre2grep ag=Silver, and presumably ripgrep since it was "soon" in 2018.

We might need to split into 2 tickets, one for More Tools and one for Comparison Table ?

n1vux avatar Jun 07 '22 03:06 n1vux