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

75942Re: Matching JUST the nth occurence of a text in a line

Expand Messages
  • Charles E Campbell Jr
    Dec 1, 2006
    • 0 Attachment
      mzyzik@... wrote:

      >On Fri, Dec 01, 2006 at 10:34:14AM -0500, Charles E Campbell Jr wrote:
      >
      >
      >>mzyzik@... wrote:
      >>
      >>
      >>
      >>>I am puzzled by a slightly more complicated version:
      >>> how to match a '%' character following the 2nd occurrence of "home"?
      >>>
      >>>
      >>>
      >>>
      >>/^.\{-}\%(home.\{-1,}\)\{N}home.\{-}\zs%
      >>
      >>
      >
      >This pattern doesn't work. Try it on this line:
      >"home home home home home home% home"
      >
      >It should match nothing on that line, because the '%' doesn't follow the
      >2nd occurrence as desired.
      >
      >
      But it *does* work! You didn't specify avoiding the % if matches to the
      home pattern intervened.
      Try
      :set hls
      and the following two lines:

      home % home home home home home% home
      home home %home home home% home

      and you'll only see %s match after the 2nd home, exactly as specified.
      Now, if you change
      the requirement, a different regex is needed.

      Regards,
      Chip Campbell
    • Show all 20 messages in this topic