Reputation: 3314
I am saving the html page as text where I want to pull out names from the file using RegEx. Nothing is being returned, I think because of the white space between the element. I tried to add \s*
between the span and anchor. PLEASE HELP me fix it...
Here is an example of the html:
<li>
<span class="name">
<a href="/players/player-name.html">Stanley, Kyle</a>
</span>
</li>
I am using C#, here is my code:
static void Main(string[] args)
{
using (StreamReader r = new StreamReader(@"textfile.txt"))
{
string content = r.ReadToEnd();
Regex r1 = new Regex("<span class=\"name\"><a.*>(.*?)</a></span>");
MatchCollection mc = r1.Matches(content);
foreach (Match m in mc)
{
Console.WriteLine(m.Groups[1].Value);
}
}
Console.ReadLine();
Console.WriteLine();
}
Upvotes: 0
Views: 250
Reputation: 39355
Regex r1 = new Regex(
@"<span class=""name"">\s*<a.*?>(.*?)</a>\s*</span>",
RegexOptions.Multiline
);
Upvotes: 1