I suck at Regex’s and am surprised I was able to get as far as I did by myself.
So far I’ve got this:
string text = "Whoa here is some very cool text.<phone>222-222-5555</phone><timesCalled>6</timescalled>";
Regex phoneRegex = new Regex(@"<phone>(.*?)<\/phone>");
Regex calledRegex = new Regex(@"<timesCalled>(.*?)<\/timesCalled>");
string phone = phoneRegex.Match(text).Value;
string timesCalled = calledRegex.Match(text).Value;
Both of these give me the full tags and the value inside, how do I make it so it only returns what is inside the tag? Also I need a final regex that would return all the text not inside those tags, so Whoa here is some very cool text. from the above example. The special tags would always appear after the normal text, if that matters.
Edit: Thanks for the answers all, I still need the final regex though (bolded above).
So far I tried this:
string pattern = @"^" + phoneRegex.Match(text).Value + calledRegex.Match(text).Value;
Regex textRegex = new Regex(pattern);
string normalText = textRegex.Match(text).Groups[1].Value;
but that is returning nothing.
You want to get the value of the group:
Groups are 1-based.