Regex to change multiple lines

Tim Chase python.list at tim.thechases.com
Thu Sep 3 10:39:32 EDT 2020


Derp, sorry about the noise.  I mistook this message for a similar
dialog over on the Vim mailing list.

For Python, you want

  re.sub(r"%%(.*?)%%", r"<del>\1</del>", s, flags=re.S)

or put the flag inline

  re.sub(r"(?s)%%(.*?)%%", r"<del>\1</del>", s)

-tim

On 2020-09-03 09:27, Tim Chase wrote:
> On 2020-09-03 16:10, Termoregolato wrote:
> > -- original
> > This is the %%text that i must modify%%, on a line, %%but also
> > on the others%% that are following
> > 
> > I need to change to
> > 
> > -- desidered
> > This is the <del>text that i must modify</del>, on a line,
> > <del>but also on the others</del> that are following  
> 
> Should be able to use
> 
>  :%s/%%\(\_.\{-}\)%%/<del>\1<\/del>/g
> 
> It simplifies slightly if you use a different delimiter
> 
>  :%s@%%\(\_.\{-}\)%%@<del>\1</del>@g
> 
> -tim
> 
> 
> 


More information about the Python-list mailing list