import std.regex; auto intRegex = regex(`\bint\b`); Document d; d.setContent("int foo(int x, uint y)\n{\n return cast(int)(x + y);\n}\n"); size_t lastIndex = size_t.max; Position lastPosition; Position[] matches; foreach (match; d.rawText.matchAll(intRegex)) matches ~= d.nextPositionBytes(lastPosition, lastIndex, match.pre.length); assert(matches == [ Position(0, 0), Position(0, 8), Position(2, 16) ]);
Calls movePositionBytes, updates src to be the return value and updates start to become end. This reduces boilerplate in common calling scenarios.