Summary: "g" on default in std.regex.match
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos

--- Comment #0 from 2012-01-09 13:52:08 PST ---
D2 code:

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, " ");

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

It outputs (DMD 2.058 Head):

["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?

Note: I have not marked this issue as "enhancement" because of this comment by
Dmitry Olshansky (found by drey_ on IRC #D):$2lpp$

> Yet I have to issue yet another warning about new std.regex compared 
> with old one:
> import std.stdio;
> import std.regex;
> void main() {
>     string src = "4.5.1";
>     foreach (c; match(src, regex(r"(\d+)")))
>         writeln(c.hit);
> }
> previously this will find all matches, now it finds only first one. To 
> get all of matches use "g" option.
> Seems like 100% compatibility was next to impossible.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to