Last active
August 9, 2021 14:28
-
-
Save pedroinfo/26b66048855feab917350d25bc05b605 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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