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

82222Re: vim | replacement question

Expand Messages
  • Nikolaos Patsopoulos
    Sep 2, 2007
      On 8/31/07, Tim Chase <vim@...> wrote:

      Tim thanks for the reply. Sorry but was away for couple of days.


      >
      > > A couple of questions:
      > > 1.

      >
      > was there a question here?

      Yes, there was. I want a text that looks like this:

      <DIV>text</DIV>
      <DIV>text</DIV>
      <DIV>text</DIV>
      <DIV>text</DIV>
      <DIV>text</DIV>

      text....
      ....
      <DIV>text</DIV>
      <DIV>text</DIV>
      <DIV>text</DIV>
      <DIV>text</DIV>

      text.....

      to be turned into this:


      <DIV>text</DIV><DIV>text</DIV><DIV>text</DIV><DIV>text</DIV><DIV>text</DIV>

      text....
      ....
      <DIV>text</DIV><DIV>text</DIV><DIV>text</DIV><DIV>text</DIV>

      text.....

      my working code:
      :%s/\(<\/DIV>\).*\n.*\(<DIV>.*<\/DIV>\)/\1\2

      results:

      <DIV>text</DIV><DIV>text</DIV>
      <DIV>text</DIV><DIV>text</DIV>
      <DIV>text</DIV>

      text....
      ....
      <DIV>text</DIV><DIV>text</DIV>
      <DIV>text</DIV><DIV>text</DIV>

      text.....

      and have to run it more than once. The problem is that this a script
      actually and don't know how many times this particular code has to be
      run eventually.

      >
      > > 2.
      I believe I oversimplified this.
      Here is a section of the text:

      <SPONSORS>Kendle International</SPONSORS><DIV>Abbott</DIV>
      <DIV>Barr Laboratories</DIV>
      <DIV>Boehringer Ingelheim Pharmaceuticals</DIV>
      <DIV>Bristol-Myers Squibb</DIV>
      <DIV>Gilead Sciences</DIV>
      <DIV>GlaxoSmithKline</DIV>
      <DIV>Hoffmann-La Roche</DIV>
      <DIV>Idenix Pharmaceuticals</DIV>
      <DIV>Merck</DIV>
      <DIV>Novartis</DIV>
      <DIV>Pfizer</DIV>
      <DIV>Ranbaxy Laboratories Ltd</DIV>
      <DIV>Tibotec Pharmaceutical Limited</DIV>

      I want to turn this to
      <SPONSORS>Kendle International</SPONSORS><SPONSORS>Abbott</SPONSORS>
      <SPONSORS>Barr Laboratories</SPONSORS>
      <SPONSORS>Boehringer Ingelheim
      Pharmaceuticals</SPONSORS>
      <SPONSORS>Bristol-Myers Squibb</SPONSORS>
      <SPONSORS>Gilead Sciences</SPONSORS>
      <SPONSORS>GlaxoSmithKline</SPONSORS>
      <SPONSORS>Hoffmann-La Roche</SPONSORS>
      <SPONSORS>Idenix Pharmaceuticals</SPONSORS>
      <SPONSORS>Merck</SPONSORS>
      <SPONSORS>Novartis</SPONSORS>
      <SPONSORS>Pfizer</SPONSORS>
      <SPONSORS>Ranbaxy Laboratories Ltd</SPONSORS>
      <SPONSORS>Tibotec Pharmaceutical
      Limited</SPONSORS>

      I cannot just turn all DIV to SPONSORS cause there are DIV tags that
      need to be unchanged. My working code does one pass each time and the
      one Tim suggested just erases the first DIV tags (my fault actually).

      > > pattern1 pattern1 pattern1 pattern1 pattern1 pattern1
      > >
      > > working code:
      > >
      > > :%s/\(pattern1\)\(pattern2\)/\1\2
      > >

      >
      > While yes, you can use a "while" loop, you may want to use a
      > "sub-replace-special" secondary call to substitute, such as
      >
      > :%s/^\(pattern1\)\s\+\(\%(pattern2\n\)\+\)/\=submatch(1).substitute(submatch(2),
      > 'pattern2\n', ' '.submatch(1), 'g')
      >
      >
      > -tim
      >


      Thanks,

      Nikos

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Show all 22 messages in this topic