How can I walk the list in a RegexMatch backwards?

Jordan Wilson wilsonjord at gmail.com
Sun Feb 3 19:03:56 UTC 2019


On Sunday, 3 February 2019 at 18:07:13 UTC, Chris Bare wrote:
> auto matches = matchAll(str, searchRegex);
>
> foreach (m; matches) // this walks the list forward
>
> I tried:
> foreach_reverse (m; matches)
> foreach (m; reverse (matches))
> foreach (m; retro (matches))
>
> and they all failed to compile.
> I also tried to index matches (matches[i]) but that does not 
> work either.

matchAll is a forward range, whereas retro requires a 
bi-directional range.
So using the array function should work:
foreach (m; matches.array.retro)

Jordan


More information about the Digitalmars-d-learn mailing list