Skip to content

Instantly share code, notes, and snippets.

@pedroinfo
Last active August 9, 2021 14:28
Show Gist options
  • Save pedroinfo/26b66048855feab917350d25bc05b605 to your computer and use it in GitHub Desktop.
Save pedroinfo/26b66048855feab917350d25bc05b605 to your computer and use it in GitHub Desktop.
static string Between(this string source, string left, string right)
{
return Regex.Match(
source,
string.Format("{0}(.*){1}", left, right))
.Groups[1].Value;
}
private static List<string> ExtractFromString(string source, string start, string end)
{
var results = new List<string>();
string pattern = string.Format(
"{0}({1}){2}",
Regex.Escape(start),
".+?",
Regex.Escape(end));
foreach (Match m in Regex.Matches(source, pattern))
{
results.Add(m.Groups[1].Value);
}
return results;
}
public static class StringExtensionMethods
{
public static List<string> EverythingBetween(this string source, string start, string end)
{
var results = new List<string>();
string pattern = string.Format(
"{0}({1}){2}",
Regex.Escape(start),
".+?",
Regex.Escape(end));
foreach (Match m in Regex.Matches(source, pattern))
{
results.Add(m.Groups[1].Value);
}
return results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment