[draft] New std.regex walkthrough

bearophile bearophileHUGS at lycos.com
Tue Mar 13 13:05:23 PDT 2012


Dmitry Olshansky:

> It's about time to break this gloomy aura, and show that std.regex is 
> actually easy to use, that it does the thing and has some nice extras.

This seems a good moment to ask people regarding this small problem, that we have already discussed a little in Bugizilla (there is a significant need to show here some Bugzilla discussions):

http://d.puremagic.com/issues/show_bug.cgi?id=7260

The problem is easy to show:

import std.stdio: write, writeln;
import std.regex: regex, match;

void main() {
    string text = "abc312de";

    foreach (c; text.match("1|2|3|4"))
        write(c, " ");
    writeln();

    foreach (c; text.match(regex("1|2|3|4", "g")))
        write(c, " ");
    writeln();
}


It outputs:

["3"] 
["3"] ["1"] ["2"]

In my code I have seen that usually the "g" option (that means "repeat over the
whole input") is what I want. So what do you think about making "g" the default?

This request is not as arbitrary as it looks, if you compare to the older API. See Bug 7260 for more info.

Bye,
bearophile


More information about the Digitalmars-d mailing list