Return to Snippet

Revision: 27155
at May 25, 2010 11:40 by blackf0rk

Initial Code
public string ParseBetween(string Subject, string Start, string End)
        return Regex.Match(Subject, Regex.Replace(Start, @"[][{}()*+?.\\^$|]", @"\$0") + @"\s*(((?!" + Regex.Replace(Start, @"[][{}()*+?.\\^$|]", @"\$0") + @"|" + Regex.Replace(End, @"[][{}()*+?.\\^$|]", @"\$0") + @").)+)\s*" + Regex.Replace(End, @"[][{}()*+?.\\^$|]", @"\$0"), RegexOptions.IgnoreCase).Value.Replace(Start, "").Replace(End, "");

Initial URL

Initial Description
This code will take a start and end string and then search for them within the subject string. It returns what is between the start and end strings. As an example, if I had the following text...

Some test text string, with a start <tag> and an end </tag>.

...I could call this function to get the text between the <tag> and the </tag> strings. This function will return: "and an end"

Initial Title
Return string from between two matched strings

Initial Tags
regex, text

Initial Language