How to replace pairs tags with regexp
Suliman via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 20 06:39:18 PDT 2017
I have got next code:
import std.stdio;
import std.regex;
import std.file;
void main()
{
auto text = readText("book.txt");
auto inlineCodeBlock = regex("`([^`\n]+)`");
auto bigCodeBlock = regex(r"`{3}[\s\S]*?`{3}");
foreach(t; text.matchAll(bigCodeBlock))
{
string t1 = t.hit.replaceFirst(regex("`"),`<code>`);
string t2 = t1.replaceFirst(regex("`"),`</code>`);
}
}
Here I am replacing `foo` to <code>foo</code>. But got replaced
data as copy, not in original document. But I need to get
replacing in original document.
replaceAll is not suitable for it because it's not clear how to
get open and close tags (<code> and </code>).
More information about the Digitalmars-d-learn
mailing list