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
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/e6c3320b1fb534ae3960077b057256bd032e4079 Fix issue 12227 - Allow matching multiple patterns in one go with std.regex https://github.com/D-Programming-Language/phobos/commit/2111157980058b6a69df8b5f2016357411b29ba1 Merge pull request #4158 from DmitryOlshansky/issue12227 Fix issue 12227 - Allow matching multiple patterns in one go with std.regex