[Issue 7260] New: "g" on default in std.regex.match
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Mon Jan  9 13:52:11 PST 2012
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=7260
           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
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 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, " ");
    writeln();
    foreach (c; text.match(regex("1|2|3|4", "g")))
        write(c, " ");
    writeln();
}
It outputs (DMD 2.058 Head):
["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?
Note: I have not marked this issue as "enhancement" because of this comment by
Dmitry Olshansky (found by drey_ on IRC #D):
http://dfeed.kimsufi.thecybershadow.net/discussion/thread/jc9hrl$2lpp$1@digitalmars.com#post-jc9mag:2430tq:241:40digitalmars.com
> 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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
    
    
More information about the Digitalmars-d-bugs
mailing list