Where do you test syntax of D regexp online?

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 9 06:53:46 PST 2017


On 10/03/2017 3:50 AM, Suliman wrote:
> I wrote two regexp:
>
> --------------------
> auto inlineCodeBlock = regex("`(.*?)`"); // -->  `(.*?)`
> auto bigCodeBlock = regex("/`{3}[\\s\\S]*?`{3}/g"); // -->
> `{3}[\s\S]*?`{3}
> --------------------
> First for for selection inline code block. Second for multi-line:
> --------------------
> #Header
> my header text
>
> ##SubHeader
> my sub header text `foo inline code`
>
> ```
> void foo()
> {
>    writeln("ppp");
> }
> ```
>
> ###Sub3Header
> my sub 3 text `bar inline code`
>
> #Header2
> my header2 text
> --------------------
>
> It's work fine in online editor https://regex101.com/r/EC5WRu/1 (sic!
> \\s\\S double escaped in D code).
>
> But after compilation of code:
>
> auto x = content.matchFirst(bigCodeBlock);
> writeln(x);
>
>
> print:
> []
> []
>
> It's seems that D regexp work in another way. How can I test them?

I would use dpaste and write a quick script but here is where I think 
your problem is:

regex("/.*/g")

It should be:

regex(".*", "g")

As per[0].

[0] http://dlang.org/phobos/std_regex.html#.regex


More information about the Digitalmars-d-learn mailing list