[Issue 12227] New: Allow matching multiple patterns in one go with std.regex
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sat Feb 22 13:38:39 PST 2014
    
    
  
https://d.puremagic.com/issues/show_bug.cgi?id=12227
           Summary: Allow matching multiple patterns in one go with
                    std.regex
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: dmitry.olsh at gmail.com
--- Comment #0 from Dmitry Olshansky <dmitry.olsh at gmail.com> 2014-02-22 13:38:38 PST ---
Synposis:
auto m = matchFirst("42 days", `[a-z]+`, `\d+`);
assert(m.index == 2); //2nd pattern match
assert(m.index != 0); //same as not empty
foreach(item; "42 days".matchAll(`[a-z]+`, `\d+`))
{
     switch(item.index){
     case 1: 
             assert(item[0] == "days");
             break;
     case 2:
             assert(item[1] == "42");
             break;
     default:
             assert(0);
     }
}
Rationale - as a more efficient common basis for pattern matching (e.g.
switch-case on with regex patterns as cases).
-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
    
    
More information about the Digitalmars-d-bugs
mailing list