Loading ...
Sorry, an error occurred while loading the content.

Re: Minimal matching regex

Expand Messages
  • fritzophrenic
    ... This is a common trap that many people (including myself) fall into when using minimal matching. Minimal matching will _NOT_ adjust the _beginning_ of a
    Message 1 of 5 , Oct 9, 2008
    • 0 Attachment
      On Oct 8, 10:41 am, Nate <Nathan.N...@...> wrote:
      > I've tried this search/replace:
      > :%s/\..\{-}$//c
      >
      > However, vim will not do minimal matching on the 3rd line.

      This is a common trap that many people (including myself) fall into
      when using minimal matching.

      Minimal matching will _NOT_ adjust the _beginning_ of a match. It only
      controls where the match _stops_ matching.

      So, here's the breakdown of your regex, as-is:

      \. : match the first '.' character in the line.
      .\{-} : match any number of any character, until the first time you
      encounter...
      $ : the end of the line

      My crack at it would look like this:

      s/\.[^.]*$//

      The \. matches a '.' character, and the [^.]*$ matches as many as
      possible NON '.' characters and the end of the line, meaning that it
      is guaranteed to match the _last_ '.' in the line.
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.