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.

7
  • 2
    and in the example given, /g would be needed to substitute more than once. Commented Mar 28, 2011 at 3:06
  • 1
    I think "non-greedy" is the more common term. At any rate, the default is greedy matching, and you want the opposite. Commented Mar 28, 2011 at 3:39
  • Note that in Gnu grep you'll need to use --perl-regexp (-P) for the lazy operator (or use the approach below). reference Commented Aug 28, 2014 at 21:52
  • Be aware of this: "XaXbXY" =~ /X(.*?)XY/ => aXb Commented May 2, 2017 at 13:46
  • @ikegami: Aware of what, it working exactly as it's supposed to? Commented May 3, 2017 at 10:54