www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How can I walk the list in a RegexMatch backwards?

reply Chris Bare <chris bareflix.com> writes:
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.
Feb 03
parent Jordan Wilson <wilsonjord gmail.com> writes:
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
Feb 03