On 4/2/07, Tobia <[EMAIL PROTECTED]> 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

Reply via email to