namespace ParseTests
{
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public static class ExtensionMethods
{
public static IEnumerable<string> GetBetween(
this string source,
string startToken,
string endToken,
bool includeTokens = false)
{
string pattern = string.Format(
"(?:{0})(.*?)(?:{1})",
Regex.Escape(startToken),
Regex.Escape(endToken));
Match match = Regex.Match(source, pattern, RegexOptions.Singleline);
while (match.Success)
{
yield return includeTokens ? match.Value : match.Groups[1].Value;
match = match.NextMatch();
}
}
}
}