user1544261
user1544261

Reputation: 3

I can't build Regular Expression

I have HTML code:

<tr class="odd"><td style="display:none">id&gt;26847504,level&gt;0,key_left&gt;0,key_right&gt;0,name&gt;Random.Stuff345345,type&gt;

I want to get those:

  1. 26847504
  2. Random.Stuff345345

I already tried that:

<tr class=\".+\"><td style=\"display:none\">id&gt;([0-9]+),level&gt;0,key_left&gt;0,key_right\&gt;0,name&gt;([^,]+),type&gt;

But it doesn't work.

Upvotes: 0

Views: 105

Answers (1)

Ωmega
Ωmega

Reputation: 43663

It is very bad idea to parse HTML with regex, but if you want to...

using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
        string input = "...";
        Match match = Regex.Match(input, @"id&gt;([^,]*).*?name&gt;([^,]*)");
        if (match.Success)
        {
            Console.WriteLine(match.Groups[1].Value);
            Console.WriteLine(match.Groups[2].Value);
        }
    }
}

Test the code here.

Upvotes: 2

Related Questions