Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Regex Solution

0 views
Skip to first unread message

Trey Balut

unread,
Dec 15, 2009, 5:27:22 PM12/15/09
to
What would be the Regex to capture the following fields from the sample
strings?

Sample Strings:

"><td>RAT</td><td>YDS</td><td>TD</td><
"><td>74.1</td><td>1,170</td><td>6</td><

"RAT" "YDS" "TD"
"74.1" "1,170" "6"

Thanks

Random

unread,
Dec 15, 2009, 6:51:21 PM12/15/09
to
On Dec 15, 2:27 pm, "Trey Balut" <treyba...@hotmail.com> wrote:
> What would be the Regex to capture the following fields from the sample
> strings?
>
> Sample Strings:
>
> "><td>RAT</td><td>YDS</td><td>TD</td><
> "><td>74.1</td><td>1,170</td><td>6</td><

Something like this would do it:

string value = "><td>74.1</td><td>1,170</td><td>6</td><";
Match m = Regex.Match(value, "<td>([^<]+)</td>");
while (m.Success)
{
Debug.WriteLine(m.Groups[1]);
m = m.NextMatch();
}


That said, if you have more complex HTML or "from the wild" HTML,
you'll be in a world of pain trying to use a Regexp parser. It's much
better to use a HTML parser like the Html Agility Pack:
http://www.codeplex.com/htmlagilitypack

Jeff Johnson

unread,
Dec 16, 2009, 9:25:35 AM12/16/09
to
"Trey Balut" <trey...@hotmail.com> wrote in message
news:54F5E83E-58D2-4DA9...@microsoft.com...

> What would be the Regex to capture the following fields from the sample
> strings?

In my opinion: Nothing. I'm on the "Don't do it" side of the "Should I use
RegEx to parse HTML?" holy war. I agree with Random, use an HTML parsing
library, and I second the suggestion of the HTML Agility Pack. I've used it
and it rocks.


Trey Balut

unread,
Dec 16, 2009, 1:21:45 PM12/16/09
to
Random and Jeff,

Thanks for the input and Random, thanks for the solution. (It worked).

Looking at Agility Pack, hummmmm, getting up to speed with Regex is a
steep climb. At first glance Agility Pack looks like Mt. Everest. I will
re-visit it and give it another chance.

Thanks again.

Trey

"Jeff Johnson" <i....@enough.spam> wrote in message
news:enAejulf...@TK2MSFTNGP05.phx.gbl...

Jeff Johnson

unread,
Dec 16, 2009, 4:08:03 PM12/16/09
to
"Trey Balut" <trey...@hotmail.com> wrote in message
news:F74917F3-54B7-415E...@microsoft.com...

> Looking at Agility Pack, hummmmm, getting up to speed with Regex is a
> steep climb. At first glance Agility Pack looks like Mt. Everest. I
> will re-visit it and give it another chance.

There will defnitely be more code involved with the HTML Agility Pack; no
doubt about it. But it will be readable code as opposed to the nightmare
(but arguably compact!) RegEx you'd have to develop to deal with "ugly"
HTML.


0 new messages