Bug 12227 – Allow matching multiple patterns in one go with std.regex
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-22T13:38:00Z
Last change time
2016-04-15T17:21:37Z
Assigned to
nobody
Creator
dmitry.olsh
Comments
Comment #0 by dmitry.olsh — 2014-02-22T13:38:38Z
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).
Comment #1 by github-bugzilla — 2016-04-15T17:21:36Z