Reputation: 3431
i have this snippet to perform a regex-search:
public IEnumerable<MyMatch> GetMyMatches()
{
Match m = myRegex.Match(Text, offset);
if (m != null && m.Success && m.Value != null && m.Value.Length > 0)
{
offset = m.Index+m.Length;
yield return new MyMatch() { Match=m, SomeFurtherInformation=... };
} else
yield break;
}
As you can see, i walk down all occourences in my text.
but how to inverse the search-direction?
thanks for your help
Upvotes: 4
Views: 1207
Reputation: 24236
You could use 'Matches' then do a 'Reverse' on the returned IEnumerable.
Upvotes: 5
Reputation: 26599
There's a RightToLeft option in RegexOptions - you may have to adjust your expression too, but that will search "backwards" for you.
Upvotes: 2