473,509 Members | 3,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regex problem

Hi all,

Thru a HttpWebRequest and HttpWebResponse I get html like this(<pre>
excluded).

<pre>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style="
padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.00</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title"
Bolibompa</span><div class="SgZText"></div></div>

</td>
</tr>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style="
padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.01</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title" >Leksakernas
hemliga liv</span><div class="SgZText">
Dockfilmserie om leksakernas egna helt otroliga värld. Serien kommer
från USA och är gjord av Jim Henson, pappa till Mupparna.
Del 9 av 13.
</div></div>
</td>
</tr>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style="
padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.30</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title" >Josef Lamm vill
också ha en människa</span><div class="SgZText">
Josef Lamm är ett litet lamm som önskar sig en liten människa att
kela med.
</div></div>
</td>
</tr>
<tr>
</pre>

The part I'm interested in is "</a><div class="SgZText">...</div>" or
"</span><div class="SgZText">...</div>".

.... = any characters

I'm trying like this

MatchCollection mcInfos = Regex.Matches(data, "(span><div
class=\"SgZText\">.*</div>)", RegexOptions.IgnoreCase);
foreach(Match m in mcInfos)
Response.Write(m.Value + "<br/>");

But I get nothing. Any one that can help?

Cheers / Senna
Nov 18 '05 #1
3 1704
Hi Tomas,

Had tried that but the problem is that it doesnt get the wanted data. In
this code for example:
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style="
padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">11.30</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title"
Försvarspropositionen</span><div class="SgZText"> Regeringens försvarspolitiska förslag.
Direktsändning från Rosenbad följt av kommentarer från opposition och
experter.
</div></div>
</td>
</tr>
<tr>

I receive "<span class="SgSVT1">11.30</span>" and that is correct cause its
in between "<div class="SgZText">...</div>" to. But the snippet I really
wanted was "Regeringens försvarspolitiska förslag.
Direktsändning från Rosenbad följt av kommentarer från opposition och
experter."

Any ideas?

/Senna

"Tomas" wrote:
Hi Senna,

I copied your code into SnippetCompiler and I tweaked the regular expression
slightly.

From the HTML i guess you are trying to extract the text located between the
div tags. I came up with the following regular expression:

"<div class=\"SgZText\">(.*)</div>"

Then use the same as before but slightly modify your foreach to
foreach(Match m in mcInfos)
Response.Write(m.Groups[1] + "<br/>");

By using the Groups[1] you target the part of the regular expression (.*)
which is all the information contained between the tags.

Try that out and let me know if it works for you.

"Senna" wrote:
Hi all,

Thru a HttpWebRequest and HttpWebResponse I get html like this(<pre>
excluded).

<pre>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style="
padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.00</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title"
Bolibompa</span><div class="SgZText"></div></div>

</td>
</tr>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style="
padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.01</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title" >Leksakernas
hemliga liv</span><div class="SgZText">
Dockfilmserie om leksakernas egna helt otroliga värld. Serien kommer
från USA och är gjord av Jim Henson, pappa till Mupparna.
Del 9 av 13.
</div></div>
</td>
</tr>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style="
padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.30</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title" >Josef Lamm vill
också ha en människa</span><div class="SgZText">
Josef Lamm är ett litet lamm som önskar sig en liten människa att
kela med.
</div></div>
</td>
</tr>
<tr>
</pre>

The part I'm interested in is "</a><div class="SgZText">...</div>" or
"</span><div class="SgZText">...</div>".

... = any characters

I'm trying like this

MatchCollection mcInfos = Regex.Matches(data, "(span><div
class=\"SgZText\">.*</div>)", RegexOptions.IgnoreCase);
foreach(Match m in mcInfos)
Response.Write(m.Value + "<br/>");

But I get nothing. Any one that can help?

Cheers / Senna

Nov 18 '05 #2
Hi,

Have to go work now so I check in again later for updates. :)

/ Senna

"Tomas" wrote:
Hi Senna,

I copied your code into SnippetCompiler and I tweaked the regular expression
slightly.

From the HTML i guess you are trying to extract the text located between the
div tags. I came up with the following regular expression:

"<div class=\"SgZText\">(.*)</div>"

Then use the same as before but slightly modify your foreach to
foreach(Match m in mcInfos)
Response.Write(m.Groups[1] + "<br/>");

By using the Groups[1] you target the part of the regular expression (.*)
which is all the information contained between the tags.

Try that out and let me know if it works for you.

"Senna" wrote:
Hi all,

Thru a HttpWebRequest and HttpWebResponse I get html like this(<pre>
excluded).

<pre>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style="
padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.00</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title"
Bolibompa</span><div class="SgZText"></div></div>

</td>
</tr>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style="
padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.01</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title" >Leksakernas
hemliga liv</span><div class="SgZText">
Dockfilmserie om leksakernas egna helt otroliga värld. Serien kommer
från USA och är gjord av Jim Henson, pappa till Mupparna.
Del 9 av 13.
</div></div>
</td>
</tr>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style="
padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.30</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title" >Josef Lamm vill
också ha en människa</span><div class="SgZText">
Josef Lamm är ett litet lamm som önskar sig en liten människa att
kela med.
</div></div>
</td>
</tr>
<tr>
</pre>

The part I'm interested in is "</a><div class="SgZText">...</div>" or
"</span><div class="SgZText">...</div>".

... = any characters

I'm trying like this

MatchCollection mcInfos = Regex.Matches(data, "(span><div
class=\"SgZText\">.*</div>)", RegexOptions.IgnoreCase);
foreach(Match m in mcInfos)
Response.Write(m.Value + "<br/>");

But I get nothing. Any one that can help?

Cheers / Senna

Nov 18 '05 #3
Hi Senna,

Rather than depending upon others to work out your Regular Expressions for
you, here is a link to a freeware Regular Expression tool that works
beautifully for building and testing Regular Expressions:

http://www.weitz.de/regex-coach/

If you use it, you probably won't ever have to ask another Regular
Expression syntax question of anyone again.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Senna" <Se***@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Hi,

Have to go work now so I check in again later for updates. :)

/ Senna

"Tomas" wrote:
Hi Senna,

I copied your code into SnippetCompiler and I tweaked the regular expression
slightly.

From the HTML i guess you are trying to extract the text located between the div tags. I came up with the following regular expression:

"<div class=\"SgZText\">(.*)</div>"

Then use the same as before but slightly modify your foreach to
foreach(Match m in mcInfos)
Response.Write(m.Groups[1] + "<br/>");

By using the Groups[1] you target the part of the regular expression (.*) which is all the information contained between the tags.

Try that out and let me know if it works for you.

"Senna" wrote:
Hi all,

Thru a HttpWebRequest and HttpWebResponse I get html like this(<pre>
excluded).

<pre>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style=" padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.00</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title"
>Bolibompa</span><div class="SgZText"></div></div>
</td>
</tr>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style=" padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.01</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title"

Leksakernas hemliga liv</span><div class="SgZText">
Dockfilmserie om leksakernas egna helt otroliga värld. Serien kommer från USA och är gjord av Jim Henson, pappa till Mupparna.
Del 9 av 13.
</div></div>
</td>
</tr>
<tr>

<td valign="top" align="right" class="SgSVT1BG" nowrap style=" padding-right: 6px "><div class="SgZText"><span
class="SgSVT1">18.30</span></div></td>

<td valign="top"><div style="padding-left: 5; padding-right: 0;
padding-top: ; padding-bottom: 4;"><span class="SgSVT1Title" >Josef Lamm vill också ha en människa</span><div class="SgZText">
Josef Lamm är ett litet lamm som önskar sig en liten människa att kela med.
</div></div>
</td>
</tr>
<tr>
</pre>

The part I'm interested in is "</a><div class="SgZText">...</div>" or
"</span><div class="SgZText">...</div>".

... = any characters

I'm trying like this

MatchCollection mcInfos = Regex.Matches(data, "(span><div
class=\"SgZText\">.*</div>)", RegexOptions.IgnoreCase);
foreach(Match m in mcInfos)
Response.Write(m.Value + "<br/>");

But I get nothing. Any one that can help?

Cheers / Senna

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2060
by: Jon Maz | last post by:
Hi All, Am getting frustrated trying to port the following (pretty simple) function to CSharp. The problem is that I'm lousy at Regular Expressions.... //from...
4
9703
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
7
2594
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b)...
6
4775
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
17
3941
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
3
2099
by: jg | last post by:
I made a mistake somewhere in my vb code and I look, check and read against the articles and help on regex, I still can't find the mistake I made. I know my test string and the test patterns...
6
4836
by: Talin | last post by:
I've run in to this problem a couple of times. Say I have a piece of text that I want to test against a large number of regular expressions, where a different action is taken based on which regex...
16
2229
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string)...
7
2214
by: =?Utf-8?B?amFj?= | last post by:
Hi, I have problems with following code and don’t find the bug : // Set ArrayList aArray = new ArrayList(); regStr = new Regex(@"\?)*(\d+)\]"); if(text != null && regStr.IsMatch(text))...
1
12135
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.