Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 3
    eegg: dot all modifier is also known as multiline. It's a modifier that changes the "." match behavior to include newlines (normally it doesn't). There's no such modifier in grep, but there is in pcregrep. Commented May 7, 2012 at 22:01
  • 2
    Correction: In most of the regex flavors that support it, the mode that allows . to match newlines is called DOTALL or single-line mode; Ruby is the only one that calls it multiline. In the other flavors, multiline is the mode that allows the anchors (^ and $) to match at line boundaries. Ruby has no equivalent mode because in Ruby they always work that way. Commented Sep 8, 2012 at 21:40
  • 7
    -P was a complete new one on me, I've been happily grepping away for years, and only using -E ... so many wasted years! - Note to self: Re-read Man pages as a (even more!) regular thing, you never digest enough switches and options. Commented Aug 15, 2013 at 2:43
  • 44
    On some platforms (like Mac OS X) grep does not support -P, but if you use egrep you can use the .*? pattern to achieve the same result. egrep -o 'start.*?end' text.html Commented Feb 21, 2014 at 16:05
  • 7
    As an extension to @SaltyNuts comment, Mac OS X does not support -P but -E would call egrep hence the suggested .*? works just fine. Commented Dec 15, 2014 at 7:12