Wednesday, December 23, 2020

Re: Substitute pattern over multiple lines

On 2020-12-23 23:18, John Cordes wrote:
>> :g/^2 TYPE tngnote//2 NOTE /s/^2 NOTE \zs\(.*\n\(\%(\D\|3 CONC
>> \).*\n\)\+\)/\='<div
>> class="xxx">'.substitute(substitute(submatch(1), '\n3 CONC ', '',
>> 'g'), '\n', '', 'g')."<\/div>\n"
>
> The last ":g..." command I listed above is working correctly
> when there are continuation lines (i.e. at least one "3 CONC" tag
> following the "2 NOTE" tag, but I think it seems to be skipping by
> the "2 NOTE" tags which do *not* have a CONC / Continuation tag.

Ah, while I'm not positive (so shooting from the hip here) I think you
want to change the

\+

(one or more continuation lines) to just

*

(zero or more continuation lines) to produce

:g/^2 TYPE tngnote//2 NOTE /s/^2 NOTE \zs\(.*\n\%(\%(\D\|3 CONC
\).*\n\)\+\)/\='<div class="xxx">'.substitute(substitute(submatch(1),
'\n3 CONC ', '', 'g'), '\n', '', 'g')."<\/div>\n"

(I also snuck in an extra "%" in the inner \(…\) which I missed when
transcribing it earlier, but shouldn't impact the results)

-tim



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201223215706.6f09714c%40bigbox.attlocal.net.

No comments:

Post a Comment