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

Re: repeat replace many time on each line

Expand Messages
  • Tobia
    ... ^^ this works: %s/ %( %(foo= ) @
    Message 1 of 5 , Apr 2 10:27 AM
    View Source
    • 0 Attachment
      Arnaud Bourree wrote:
      > I've Xml document with attribute likes:
      > foo="00 12 AF"
      > I want to replace with:
      > foo="0x00 0x12 0xAF"
      >
      > %s/\%(\%(foo=\"\)\@<=\%(0x[0-9A-F]\{2\}\s\)*\)\@<=\([0-9A-F]\{2\}\)/0x\1/g
      ^^
      this works:

      %s/\%(\%(foo=\"\)\@<=\%([0-9A-F]\{2\}\s\)*\)\@<=\([0-9A-F]\{2\}\)/0x\1/g


      Tobia
    • Bob Hiestand
      ... In using :s with the /g flag, I take it the potential changes are marked first, and then executed, per line? Somewhat more generally, the pattern above
      Message 2 of 5 , Apr 2 1:38 PM
      View Source
      • 0 Attachment
        On 4/2/07, Tobia <tobia.conforto@...> wrote:
        > Arnaud Bourree wrote:
        > > I've Xml document with attribute likes:
        > > foo="00 12 AF"
        > > I want to replace with:
        > > foo="0x00 0x12 0xAF"
        > >
        > > %s/\%(\%(foo=\"\)\@<=\%(0x[0-9A-F]\{2\}\s\)*\)\@<=\([0-9A-F]\{2\}\)/0x\1/g
        >
        > this works:
        >
        > %s/\%(\%(foo=\"\)\@<=\%([0-9A-F]\{2\}\s\)*\)\@<=\([0-9A-F]\{2\}\)/0x\1/g

        In using :s with the /g flag, I take it the potential changes are
        marked first, and then executed, per line?

        Somewhat more generally, the pattern above could be:

        %s/\%(\%(foo=\"\)\@<=\%(\%(0x\)\?[0-9A-F]\{2\}\s\)*\)\@<=\([0-9A-F]\{2\}\)/0x\1/g

        which works both with and (repeatedly) without the /g flag.

        I prefer when dealing with that many special characters to use the
        very-magic form:

        %s/\v%(%(foo\=")@<=%(%(0x)?[0-9A-F]{2}\s)*)@<=([0-9A-F]{2})/0x\1/g

        ... but that's obviously a matter of personal preference.

        Thank you,

        bob
      • Tobia
        ... It would seem so. By the way, I would have used a simpler pattern for such a task: %s/ v%(foo = [^ ]*)@ )/0x 1/g ... Me too. I can t stand trying
        Message 3 of 5 , Apr 2 2:51 PM
        View Source
        • 0 Attachment
          Bob Hiestand wrote:
          > Tobia wrote:
          > > Arnaud Bourree wrote:
          > > > I've Xml document with attribute likes:
          > > > foo="00 12 AF"
          > > > I want to replace with:
          > > > foo="0x00 0x12 0xAF"
          > >
          > > this works:
          > >
          > > %s/\%(\%(foo=\"\)\@<=\%([0-9A-F]\{2\}\s\)*\)\@<=\([0-9A-F]\{2\}\)/0x\1/g
          >
          > In using :s with the /g flag, I take it the potential changes are
          > marked first, and then executed, per line?

          It would seem so.

          By the way, I would have used a simpler pattern for such a task:

          %s/\v%(foo\="[^"]*)@<=(<\x\x>)/0x\1/g


          > I prefer when dealing with that many special characters to use the
          > very-magic form

          Me too. I can't stand trying to match \( \) with my eyes, they just
          don't look right, not to mention \{ \? \+... Egrep and Perl have it
          right. I wish I could turn very-magic on by default.


          Tobia
        • Arnaud Bourree
          ... Thanks that is exactly what I expect: it works for all values listed in foo attribute. I don t need to repeat the command. Good lesson for me today: keep
          Message 4 of 5 , Apr 3 12:50 AM
          View Source
          • 0 Attachment
            Tobia wrote on 02/04/2007 23:51:
            > Bob Hiestand wrote:
            >> Tobia wrote:
            >>> Arnaud Bourree wrote:
            >>>> I've Xml document with attribute likes:
            >>>> foo="00 12 AF"
            >>>> I want to replace with:
            >>>> foo="0x00 0x12 0xAF"
            >>> this works:
            >>>
            >>> %s/\%(\%(foo=\"\)\@<=\%([0-9A-F]\{2\}\s\)*\)\@<=\([0-9A-F]\{2\}\)/0x\1/g
            >> In using :s with the /g flag, I take it the potential changes are
            >> marked first, and then executed, per line?
            >
            > It would seem so.
            >
            > By the way, I would have used a simpler pattern for such a task:
            >
            > %s/\v%(foo\="[^"]*)@<=(<\x\x>)/0x\1/g
            Thanks that is exactly what I expect: it works for all values listed in
            foo attribute. I don't need to repeat the command.
            Good lesson for me today: keep it simple ;-)
            >
            >
            >> I prefer when dealing with that many special characters to use the
            >> very-magic form
            >
            > Me too. I can't stand trying to match \( \) with my eyes, they just
            > don't look right, not to mention \{ \? \+... Egrep and Perl have it
            > right. I wish I could turn very-magic on by default.
            >
            >
            > Tobia
            >

            --
            Reclaim Your Inbox!
            http://www.mozilla.org/products/thunderbird
          Your message has been successfully submitted and would be delivered to recipients shortly.