How to replace pairs tags with regexp

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 20 11:01:03 PDT 2017


Question above do not actual now. Now I have got next problem.

import std.stdio;
import std.regex;
import std.file;

void main()
{
     auto text = "#Header
     my header text

     ##SubHeader
     my sub header text

     ###Sub3Header
     my sub 3 text

     #Header2
     my header2 text";

     auto l1 = regex(`(^|\n)#([^#]*)\n([\^]*)(?=\n#[^#]|$)`, ['g', 
'm']);

     foreach(t; text.matchAll(l1))
     {
         writeln(t.hit);
     }
}


This code is print to console:

#Header
my header text

How can I modify regex to get it print:

#Header
my header text

##SubHeader
my sub header text

?

I tried different combination, some of them are working in online 
regexp editors, but do not working in D.


More information about the Digitalmars-d-learn mailing list