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

Re: Truncate matched pattern

Expand Messages
  • Benji Fisher
    ... Maybe + is more elegant than * , since it avoids changing nothing to nothing, but it is one character longer. ... BTW, both these solutions run into
    Message 1 of 3 , May 11, 2004
      Another solution:

      :%s/<NAME>.\{30}\zs.*\ze<MEMO>//

      Maybe '\+' is more elegant than '*', since it avoids "changing nothing
      to nothing," but it is one character longer.

      :help /\zs

      BTW, both these solutions run into trouble if you have multiple <NAME>
      and/or <MEMO> tags on the same line, but I guess that is not a problem
      for you.

      HTH --Benji Fisher

      On Mon, May 10, 2004 at 09:47:56PM -0700, Arun Easi wrote:
      > How about
      >
      > :%s/\(<NAME>\)\(.\{30}\).*\(<MEMO>\)/\1\2\3/
      >
      > -Arun
      >
      > On Mon, 10 May 2004, Wes Garrison wrote:
      >
      > >
      > > While trying to download my banking info from my bank, I found that they had
      > > switched (I think) the NAME and MEMO fields. I want to categorize by who I
      > > paid, not have each payee be "Downloaded from ..."
      > >
      > > I can switch the name and memo fields easily enough. However, the memo
      > > field can be longer than the name field, so I need to take text between a
      > > <NAME> tag and a <MEMO> tag and chop off after the 30th character.
      > >
      > > So:
      > > <NAME>1234567890123456789012345678901234567890<MEMO>
      > > would become . . .
      > > <NAME>123456789012345678901234567890<MEMO>
      > >
      > > Strings less than 30 characters wouldn't be messed with.
      > >
      > > I've tried various combinations and such of the following match:
      > > %s/\(<NAME>\)\(.\{-}\)\(<MEMO>\)/<NAME>\2\{,30}<MEMO>/g
      > >
      > > I get the correct string to match, and my \2 pulls the correct string.
      > > I just can't figure out how to truncate it down to the first 30.
      > >
      > > Please! Guide me as I search for the perfect regular expression!
      > >
      > > Thanks!
      > >
      > > -- Wes
      > >
      > > Dunno if it matters, but I'm using vim 6.1 on Windows.
      > >
    Your message has been successfully submitted and would be delivered to recipients shortly.