Regular Expressions

N

norton

Hi All,

I am defining a simple regular expressuions to capture some data from
specific content
I expected i can got 5 matches cases. However, i can only got 1 match and
the result is not as same as mine.

Can anyone tell me what's wrong with my regular exprssions pattern? Thx in
advance

Regards,
Norton

My Code
-------------------------------------------
Imports System.Text.RegularExpressions

Dim regex = New Regex( _
"<td\swidth=""30"">(?<Point>\w*)</td>.*<td>(?<Result>\w*)</td>", _
RegexOptions.Singleline _
Or RegexOptions.Compiled _
)

The source HTML code
---------------------------------------------
<table width="100%" border="0" cellspacing="5" cellpadding="2">
<tr>
<td width="30">Point1</td>
<td>A</td>
</tr>
<tr>
<td width="30">Point2</td>
<td>B</td>
</tr>
<tr>
<td width="30">Point3</td>
<td>C</td>
</tr>
<tr>
<td width="30">Point4</td>
<td>D</td>
</tr>
<tr>
<td width="30">Point5</td>
<td>E</td>
</tr>
</table>
 
J

Jay B. Harlow [MVP - Outlook]

Norton,
When you use ".*" in your pattern it looks for the longest match possible,
so it finds point="Point1" & result="E".

However if you use ".*?" in your pattern it will look for the shortest match
possible, so it then finds all 5 point/result pairs.

Change your expression something like:
Dim regex = New Regex( _
"<td\swidth=""30"">(?<Point>\w*)</td>.*<td>(?<Result>\w*)</td>", _

RegexOptions.Singleline _
Or RegexOptions.Compiled _
)

"?" is a "lazy" quantifier, causing the pattern to support minimal
matching...

Hope this helps
Jay
 
A

Adam Goossens

Hi norton,

Jay has already given you the answer I would've, but I thought I should
point you to this little gem of a program:

Expresso [ http://www.ultrapico.com/Expresso.htm ]

Expresso is a regular expression tester, analyzer and profiler. My
favourite part is the Expression Analyzer, which will translate a
regular expression into English for you. Very, very handy, especially
with complex regular expressions.

Regards,
-Adam.
 
J

Jay B. Harlow [MVP - Outlook]

Adam,
Hey thanks!

I will have to book mark that one!

I've used RegEx Workbench
http://www.gotdotnet.com/Community/...mpleGuid=c712f2df-b026-4d58-8961-4ee2729d7322,
but normally I just write 5 or 6 lines in a VB.NET program...

Thanks
Jay

Adam Goossens said:
Hi norton,

Jay has already given you the answer I would've, but I thought I should
point you to this little gem of a program:

Expresso [ http://www.ultrapico.com/Expresso.htm ]

Expresso is a regular expression tester, analyzer and profiler. My
favourite part is the Expression Analyzer, which will translate a regular
expression into English for you. Very, very handy, especially with complex
regular expressions.

Regards,
-Adam.
Hi All,

I am defining a simple regular expressuions to capture some data from
specific content
I expected i can got 5 matches cases. However, i can only got 1 match and
the result is not as same as mine.

Can anyone tell me what's wrong with my regular exprssions pattern? Thx
in
advance

Regards,
Norton

My Code
-------------------------------------------
Imports System.Text.RegularExpressions

Dim regex = New Regex( _
"<td\swidth=""30"">(?<Point>\w*)</td>.*<td>(?<Result>\w*)</td>", _
RegexOptions.Singleline _
Or RegexOptions.Compiled _
)

The source HTML code
---------------------------------------------
<table width="100%" border="0" cellspacing="5" cellpadding="2">
<tr>
<td width="30">Point1</td>
<td>A</td>
</tr>
<tr>
<td width="30">Point2</td>
<td>B</td>
</tr>
<tr>
<td width="30">Point3</td>
<td>C</td>
</tr>
<tr>
<td width="30">Point4</td>
<td>D</td>
</tr>
<tr>
<td width="30">Point5</td>
<td>E</td>
</tr>
</table>
 
J

Jay B. Harlow [MVP - Outlook]

Adam,
Your URL comes up with a DNS error?

Using Google I found:

http://www12.brinkster.com/ultrapico/Expresso.htm

Thanks
Jay

Adam Goossens said:
Hi norton,

Jay has already given you the answer I would've, but I thought I should
point you to this little gem of a program:

Expresso [ http://www.ultrapico.com/Expresso.htm ]

Expresso is a regular expression tester, analyzer and profiler. My
favourite part is the Expression Analyzer, which will translate a regular
expression into English for you. Very, very handy, especially with complex
regular expressions.

Regards,
-Adam.
Hi All,

I am defining a simple regular expressuions to capture some data from
specific content
I expected i can got 5 matches cases. However, i can only got 1 match and
the result is not as same as mine.

Can anyone tell me what's wrong with my regular exprssions pattern? Thx
in
advance

Regards,
Norton

My Code
-------------------------------------------
Imports System.Text.RegularExpressions

Dim regex = New Regex( _
"<td\swidth=""30"">(?<Point>\w*)</td>.*<td>(?<Result>\w*)</td>", _
RegexOptions.Singleline _
Or RegexOptions.Compiled _
)

The source HTML code
---------------------------------------------
<table width="100%" border="0" cellspacing="5" cellpadding="2">
<tr>
<td width="30">Point1</td>
<td>A</td>
</tr>
<tr>
<td width="30">Point2</td>
<td>B</td>
</tr>
<tr>
<td width="30">Point3</td>
<td>C</td>
</tr>
<tr>
<td width="30">Point4</td>
<td>D</td>
</tr>
<tr>
<td width="30">Point5</td>
<td>E</td>
</tr>
</table>
 
J

Jay B. Harlow [MVP - Outlook]

Cor,
Interesting, I'm getting a "The page cannot be displayed" ... "Connect find
server or DNS Error".

If I try the brinkster link, I get the same error on the comcast.net site,
when I try to download (or the page tries the images).

I'll try again later, it sounds like someone's DNS server is having
issues...

Jay
 
N

norton

Thx all of you
it works well

Really happy to learn from yours! Cheers!
Regards,
Norton
 
H

Herfried K. Wagner [MVP]

Jay B. Harlow said:
Interesting, I'm getting a "The page cannot be displayed" ... "Connect
find server or DNS Error".

The link works fine for me too. Hopefully it's a temporary problem that
will be fixed soon ;-).
 
J

Jay B. Harlow [MVP - Outlook]

Herfried,
Its working now here also...

Jay

Herfried K. Wagner said:
The link works fine for me too. Hopefully it's a temporary problem that
will be fixed soon ;-).
 
A

Adam Goossens

Jay,

I've never heard of RegEx Workbench before - I downloaded it and it
looks like a good program! I like the easy access to the operators and
what-not from the "Add Item" menu - great for people like me who needs
reminding of these things sometimes :)

The only problem I've had with Expresso so far is that I haven't been
able to register it :p I've sent off the e-mail like they asked, but no
response. I think I might go and rustle them up about it.

PS: Damn fiesty DNS servers :)

Thanks!
-Adam.
Adam,
Hey thanks!

I will have to book mark that one!

I've used RegEx Workbench
http://www.gotdotnet.com/Community/...mpleGuid=c712f2df-b026-4d58-8961-4ee2729d7322,
but normally I just write 5 or 6 lines in a VB.NET program...

Thanks
Jay

Hi norton,

Jay has already given you the answer I would've, but I thought I should
point you to this little gem of a program:

Expresso [ http://www.ultrapico.com/Expresso.htm ]

Expresso is a regular expression tester, analyzer and profiler. My
favourite part is the Expression Analyzer, which will translate a regular
expression into English for you. Very, very handy, especially with complex
regular expressions.

Regards,
-Adam.
Hi All,

I am defining a simple regular expressuions to capture some data from
specific content
I expected i can got 5 matches cases. However, i can only got 1 match and
the result is not as same as mine.

Can anyone tell me what's wrong with my regular exprssions pattern? Thx
in
advance

Regards,
Norton

My Code
-------------------------------------------
Imports System.Text.RegularExpressions

Dim regex = New Regex( _
"<td\swidth=""30"">(?<Point>\w*)</td>.*<td>(?<Result>\w*)</td>", _
RegexOptions.Singleline _
Or RegexOptions.Compiled _
)

The source HTML code
---------------------------------------------
<table width="100%" border="0" cellspacing="5" cellpadding="2">
<tr>
<td width="30">Point1</td>
<td>A</td>
</tr>
<tr>
<td width="30">Point2</td>
<td>B</td>
</tr>
<tr>
<td width="30">Point3</td>
<td>C</td>
</tr>
<tr>
<td width="30">Point4</td>
<td>D</td>
</tr>
<tr>
<td width="30">Point5</td>
<td>E</td>
</tr>
</table>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top