Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
| Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 5th, 2008, 06:32 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default Matching Numeric Strings with RegEx

Hello Everyone and thansk for your help in advance. I am working on an application that needs to parse links withing HTML. First, here are a few of the strings I am trying to work with:

profile.asp?LicId=87803&ProfNBR=1501

profile.asp?LicId=5934&ProfNBR=1901

As you can see, the numeric string after the LicId= is variable in length. I actually don't need to match anything after the numeric portion, so I can let the & termminate the match. The code I have tried is:

Dim MatchPattern As String = "profile.asp\?LicId\=[\d{2-6}]"

Dim mcLinks As MatchCollection
Dim mcLink As Match

mcLinks = Regex.Matches(html, MatchPattern, RegexOptions.IgnoreCase)
For Each mcLink In mcLinks
    LinkData = LinkData & mcLink.ToString & vbCrLf
Next

However, the output returned is:

profile.asp?LicId=8
profile.asp?LicId=5

Not really sure why this isn't working. Once again, thanks for the help.


 
Old October 5th, 2008, 09:05 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Can you try the following:

profile.asp\?LicId\=\d{2,6}

Cheers
Shasur

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old October 5th, 2008, 02:56 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I'm sure Shasur is right.

When you enclose something in [...] in a regular expression, that means you are allowing a choice of ANY ONE of the characters inside the [...].

So [\d{2-6}] means "allow either a digit or a { or a 2,3,4,5, or 6 or a }". One character, only, from those choices.
 
Old October 7th, 2008, 12:13 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for the delay in gettinng back. Thanks so much for the help. It worked fine.





Similar Threads
Thread Thread Starter Forum Replies Last Post
From numeric to alfa numeric ebekir XSLT 1 August 10th, 2007 06:13 AM
Regex and Alphanumeric matching? quantass BOOK: Beginning Regular Expressions 0 March 10th, 2007 11:34 AM
Matching two strings jamie_t VB How-To 0 October 12th, 2005 03:40 AM
Numeric Up Down Kunkel General .NET 0 April 16th, 2004 10:07 AM
Finding a matching value Morry Excel VBA 2 March 26th, 2004 05:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.