Reputation: 19
I have a C# Regex as follows:
Regex r = new Regex(@"(?<value1>.*?)<a.*?href=(""|')(?<href>.*?)(""|').*?>(?<value2>.*?)</a>(?<value3>.*?)");
I can get text for value1, href, value2 perfect. However, value3 is always "".
What am I missing to get the text that comes after the anchor closing tag().
Upvotes: 0
Views: 935
Reputation: 70722
You wouldn't return a null value if you would use a Parser instead, since parsing HTML with regular expression is not the best way to approach this. But to fix the issue, remove the non-greedy quantifier from the end of your expression making it greedy (matching the most amount possible).
(?<value3>.*?)
^ Remove non-greedy quantifier
And make it greedy:
(?<value3>.*)
See Live Demo
Upvotes: 6