473,700 Members | 2,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing Files with Regular Expressions

Hi everyone,

I'm trying to parse through the contents of some text files with regular
expressions, but am new to regular expressions and how to use them in
VB.net.

I'm pretty sure that the regular expressions are correct as I got them from
regexlib.com and tested them in the Regulator and Expresso.

The problem is I tested this function with a file that contains a string
which should be seen by the SSNRegex. This makes me think that something is
definitely wrong in my program.

Any help would be awesome.

Thanks in advance.

Chris

Code to follow:

Imports System.Text.Reg ularExpressions
''' <summary>
''' U.S. social security numbers (SSN), within the range of numbers
''' that have been currently allocated. Matches the pattern AAA-GG-SSSS,
''' AAA GG SSSS, AAA-GG SSSS, AAA GG-SSSS, AAAGGSSSS, AAA-GGSSSS,
AAAGG-SSSS,
''' AAAGG SSSS or AAA GGSSSS. All zero in any one field is not allowed.
'''** Additionally, spaces and/or dashes and/or nothing are allowed.
''' Thanks to Joe Johnston and Regexlib.com for this Regex
''' </summary>
''' <remarks></remarks>
Dim ssnRegex As String = "^(?!000)([0-6]\d{2}|7([0-6]\d|7[012])) ([ -])?
(?!00)\d\d([ -|])? (?!0000)\d{4}$"
''' <summary>
''' Matches major credit cards including: Visa (length 16, prefix 4);
''' Mastercard (length 16, prefix 51-55);
''' Diners Club/Carte Blanche (length 14, prefix 36, 38, or 300-305);
''' Discover (length 16, prefix 6011); American Express (length 15,
prefix 34 or 37).
''' Saves the card type as a named group to facilitate further
validation against a "card type";
''' checkbox in a program. All 16 digit formats are grouped 4-4-4-4
with an optional hyphen or
''' space between each group of 4 digits. The American Express format is
grouped 4-6-5 with an
''' optional hyphen or space between each group of digits. Formatting
characters must be consistant,
''' i.e. if two groups are separated by a hyphen, all groups must be
separated by a hyphen for a
''' match to occur. Thanks to Steven Smith and Regexlib.com for this
Regex
''' </summary>
''' <remarks></remarks>
Dim creditCardRegex As String =
"^(?:(?<Visa>4\ d{3})|(?<Master card>5[1-5]\d{2})|(?<Disco ver>6011)|(?<Di nersClub>(?:3[68]\d{2})|(?:30[0-5]\d))|(?<America nExpress>3[47]\d{2}))([
-]?)(?(DinersClub )(?:\d{6}\1\d{4 })|(?(AmericanE xpress)(?:\d{6} \1\d{5})|(?:\d{ 4}\1\d{4}\1\d{4 })))$" Dim options As System.Text.Reg ularExpressions .RegexOptions = _ (System.Text.Re gularExpression s.RegexOptions. IgnorePatternWh itespaceOr _ System.Text.Reg ularExpressions .RegexOptions.S ingleline Or _ System.Text.Reg ularExpressions .RegexOptions.C ompiled Or _ System.Text.Reg ularExpressions .RegexOptions.I gnoreCase) Dim ssnRegex As New Regex(RegExType s.ssnRegex, RegExTypes.opti ons) Dim creditCardRegex As New Regex(RegExType s.creditCardReg ex,RegExTypes.o ptions) Public Function CheckContents(B yVal Filename As String, ByRefFileConten ts As String) As Boolean '''''Check File Contents Against Regex''''' 'Not sure if this is correct. Dim ssnMatches As MatchCollection =ssnRegex.Match es(FileContents ) Dim creditCardMatch es As MatchCollection =creditCardRege x.Matches(FileC ontents) '''''Process any Matches''''' 'SSN matches For Each match As Match In ssnMatches Dim newFoundItem As New foundItem newFoundItem.fi leName = Filename newFoundItem.Ty peOfAsset = SSN foundItemsArray .Add(newFoundIt em) Next 'Credit Card matches For Each match As Match In creditCardMatch es 'Create a New Found Item Dim newFoundItem As New foundItem 'foundItem is just astruct in another file 'Set the File location newFoundItem.fi leName = Filename'Here I'm trying to capture the named grouped from the regex. Not sure ifthis is correct. 'Determine the CreditCard type by Regex match group Select Case True Case "Visa" = match.Groups.It em("Visa").Valu e newFoundItem.Ty peOfAsset = VISA Case "Mastercard " =match.Groups.I tem("Mastercard ").Value newFoundItem.Ty peOfAsset = MASTERCARD Case "DinersClub " =match.Groups.I tem("DinersClub ").Value newFoundItem.Ty peOfAsset = DINERS_CLUB Case "AmericanExpres s" =match.Groups.I tem("AmericanEx press").Value newFoundItem.Ty peOfAsset = AMERICAN_EXPRES S Case Else newFoundItem.Ty peOfAsset = CREDITCARD End Select 'Add the newFoundItem to our array foundItemsArray .Add(newFoundIt em) Next If ssnMatches.Coun t 0 Or creditCardMatch es.Count 0 Then Return True Else Return False End If End Function

Jul 26 '06 #1
3 2546
Here is a more readable version of the code.
1.. Imports System.Text.Reg ularExpressions
2..
3..
4..
5..
6.. ''' <summary>
7.. ''' U.S. social security numbers (SSN), within the range of numbers
8.. ''' that have been currently allocated. Matches the pattern AAA-GG-SSSS,
9.. ''' AAA GG SSSS, AAA-GG SSSS, AAA GG-SSSS, AAAGGSSSS, AAA-GGSSSS, AAAGG-SSSS,
10.. ''' AAAGG SSSS or AAA GGSSSS. All zero in any one field is not allowed.
11.. '''** Additionally, spaces and/or dashes and/or nothing are allowed.
12.. ''' Thanks to Joe Johnston and Regexlib.com for this Regex
13.. ''' </summary>
14.. ''' <remarks></remarks>
15.. Dim ssnRegex As String = "^(?!000)([0-6]\d{2}|7([0-6]\d|7[012])) ([ -])? (?!00)\d\d([ -|])? (?!0000)\d{4}$"
16.. ''' <summary>
17.. ''' Matches major credit cards including: Visa (length 16, prefix 4);
18.. ''' Mastercard (length 16, prefix 51-55);
19.. ''' Diners Club/Carte Blanche (length 14, prefix 36, 38, or 300-305);
20.. ''' Discover (length 16, prefix 6011); American Express (length 15, prefix 34 or 37).
21.. ''' Saves the card type as a named group to facilitate further validation against a "card type";
22.. ''' checkbox in a program. All 16 digit formats are grouped 4-4-4-4 with an optional hyphen or
23.. ''' space between each group of 4 digits. The American Express format is grouped 4-6-5 with an
24.. ''' optional hyphen or space between each group of digits. Formatting characters must be consistant,
25.. ''' i.e. if two groups are separated by a hyphen, all groups must be separated by a hyphen for a
26.. ''' match to occur. Thanks to Steven Smith and Regexlib.com for this Regex
27.. ''' </summary>
28.. ''' <remarks></remarks>
29.. Dim creditCardRegex As String = "^(?:(?<Visa>4\ d{3})|(?<Master card>5[1-5]\d{2})|(?<Disco ver>6011)|(?<Di nersClub>(?:3[68]\d{2})|(?:30[0-5]\d))|(?<America nExpress>3[47]\d{2}))([ -]?)(?(DinersClub )(?:\d{6}\1\d{4 })|(?(AmericanE xpress)(?:\d{6} \1\d{5})|(?:\d{ 4}\1\d{4}\1\d{4 })))$"
30..
31..
32.. Dim options As System.Text.Reg ularExpressions .RegexOptions = _
33.. (System.Text.Re gularExpression s.RegexOptions. IgnorePatternWh itespace Or _
34.. System.Text.Reg ularExpressions .RegexOptions.S ingleline Or _
35.. System.Text.Reg ularExpressions .RegexOptions.C ompiled Or _
36.. System.Text.Reg ularExpressions .RegexOptions.I gnoreCase)
37..
38..
39.. Dim ssnRegex As New Regex(RegExType s.ssnRegex, RegExTypes.opti ons)
40.. Dim creditCardRegex As New Regex(RegExType s.creditCardReg ex, RegExTypes.opti ons)
41..
42..
43.. Public Function CheckContents(B yVal Filename As String, ByRef FileContents As String) As Boolean
44..
45..
46.. '''''Check File Contents Against Regex'''''
47.. 'Dim matches As MatchCollection = Regex.Matches(i nputString,rege x,regexOptions)
48.. Dim ssnMatches As MatchCollection = ssnRegex.Matche s(FileContents)
49.. Dim creditCardMatch es As MatchCollection = creditCardRegex .Matches(FileCo ntents)
50..
51.. '''''Process any Matches'''''
52.. 'SSN matches
53.. For Each match As Match In ssnMatches
54.. Dim newFoundItem As New foundItem
55.. newFoundItem.fi leName = Filename
56.. newFoundItem.Ty peOfAsset = SSN
57.. foundItemsArray .Add(newFoundIt em)
58.. Next
59..
60.. 'Credit Card matches
61.. For Each match As Match In creditCardMatch es
62.. 'Create a New Found Item
63.. Dim newFoundItem As New foundItem
64.. 'Set the File location
65.. newFoundItem.fi leName = Filename
66..
67.. 'Determine the CreditCard type by Regex match group
68.. Select Case True
69.. Case "Visa" = match.Groups.It em("Visa").Valu e
70.. newFoundItem.Ty peOfAsset = VISA
71.. Case "Mastercard " = match.Groups.It em("Mastercard" ).Value
72.. newFoundItem.Ty peOfAsset = MASTERCARD
73.. Case "DinersClub " = match.Groups.It em("DinersClub" ).Value
74.. newFoundItem.Ty peOfAsset = DINERS_CLUB
75.. Case "AmericanExpres s" = match.Groups.It em("AmericanExp ress").Value
76.. newFoundItem.Ty peOfAsset = AMERICAN_EXPRES S
77.. Case Else
78.. newFoundItem.Ty peOfAsset = CREDITCARD
79.. End Select
80.. 'Add the newFoundItem to our array
81.. foundItemsArray .Add(newFoundIt em)
82..
83.. Next
84..
85.. If ssnMatches.Coun t 0 Or creditCardMatch es.Count 0 Then
86.. Return True
87.. Else
88.. Return False
89.. End If
90..
91.. End Function
"Chris" <co***********@ nospam.yahoo.co mwrote in message news:uO******** *****@TK2MSFTNG P02.phx.gbl...
Hi everyone,

I'm trying to parse through the contents of some text files with regular
expressions, but am new to regular expressions and how to use them in
VB.net.

I'm pretty sure that the regular expressions are correct as I got them from
regexlib.com and tested them in the Regulator and Expresso.

The problem is I tested this function with a file that contains a string
which should be seen by the SSNRegex. This makes me think that something is
definitely wrong in my program.

Any help would be awesome.

Thanks in advance.

Chris

Code to follow:

Imports System.Text.Reg ularExpressions
''' <summary>
''' U.S. social security numbers (SSN), within the range of numbers
''' that have been currently allocated. Matches the pattern AAA-GG-SSSS,
''' AAA GG SSSS, AAA-GG SSSS, AAA GG-SSSS, AAAGGSSSS, AAA-GGSSSS,
AAAGG-SSSS,
''' AAAGG SSSS or AAA GGSSSS. All zero in any one field is not allowed.
'''** Additionally, spaces and/or dashes and/or nothing are allowed.
''' Thanks to Joe Johnston and Regexlib.com for this Regex
''' </summary>
''' <remarks></remarks>
Dim ssnRegex As String = "^(?!000)([0-6]\d{2}|7([0-6]\d|7[012])) ([ -])?
(?!00)\d\d([ -|])? (?!0000)\d{4}$"
''' <summary>
''' Matches major credit cards including: Visa (length 16, prefix 4);
''' Mastercard (length 16, prefix 51-55);
''' Diners Club/Carte Blanche (length 14, prefix 36, 38, or 300-305);
''' Discover (length 16, prefix 6011); American Express (length 15,
prefix 34 or 37).
''' Saves the card type as a named group to facilitate further
validation against a "card type";
''' checkbox in a program. All 16 digit formats are grouped 4-4-4-4
with an optional hyphen or
''' space between each group of 4 digits. The American Express format is
grouped 4-6-5 with an
''' optional hyphen or space between each group of digits. Formatting
characters must be consistant,
''' i.e. if two groups are separated by a hyphen, all groups must be
separated by a hyphen for a
''' match to occur. Thanks to Steven Smith and Regexlib.com for this
Regex
''' </summary>
''' <remarks></remarks>
Dim creditCardRegex As String =
"^(?:(?<Visa>4\ d{3})|(?<Master card>5[1-5]\d{2})|(?<Disco ver>6011)|(?<Di nersClub>(?:3[68]\d{2})|(?:30[0-5]\d))|(?<America nExpress>3[47]\d{2}))([
-]?)(?(DinersClub )(?:\d{6}\1\d{4 })|(?(AmericanE xpress)(?:\d{6} \1\d{5})|(?:\d{ 4}\1\d{4}\1\d{4 })))$" Dim options As System.Text.Reg ularExpressions .RegexOptions = _ (System.Text.Re gularExpression s.RegexOptions. IgnorePatternWh itespaceOr _ System.Text.Reg ularExpressions .RegexOptions.S ingleline Or _ System.Text.Reg ularExpressions .RegexOptions.C ompiled Or _ System.Text.Reg ularExpressions .RegexOptions.I gnoreCase) Dim ssnRegex As New Regex(RegExType s.ssnRegex, RegExTypes.opti ons) Dim creditCardRegex As New Regex(RegExType s.creditCardReg ex,RegExTypes.o ptions) Public Function CheckContents(B yVal Filename As String, ByRefFileConten ts As String) As Boolean '''''Check File Contents Against Regex''''' 'Not sure if this is correct. Dim ssnMatches As MatchCollection =ssnRegex.Match es(FileContents ) Dim creditCardMatch es As MatchCollection =creditCardRege x.Matches(FileC ontents) '''''Process any Matches''''' 'SSN matches For Each match As Match In ssnMatches Dim newFoundItem As New foundItem newFoundItem.fi leName = Filename newFoundItem.Ty peOfAsset = SSN foundItemsArray .Add(newFoundIt em) Next 'Credit Card matches For Each match As Match In creditCardMatch es 'Create a New Found Item Dim newFoundItem As New foundItem 'foundItem is just astruct in another file 'Set the File location newFoundItem.fi leName = Filename'Here I'm trying to capture the named grouped from the regex. Not sure ifthis is correct. 'Determine the CreditCard type by Regex match group Select Case True Case "Visa" = match.Groups.It em("Visa").Valu e newFoundItem.Ty peOfAsset = VISA Case "Mastercard " =match.Groups.I tem("Mastercard ").Value newFoundItem.Ty peOfAsset = MASTERCARD Case "DinersClub " =match.Groups.I tem("DinersClub ").Value newFoundItem.Ty peOfAsset = DINERS_CLUB Case "AmericanExpres s" =match.Groups.I tem("AmericanEx press").Value newFoundItem.Ty peOfAsset = AMERICAN_EXPRES S Case Else newFoundItem.Ty peOfAsset = CREDITCARD End Select 'Add the newFoundItem to our array foundItemsArray .Add(newFoundIt em) Next If ssnMatches.Coun t 0 Or creditCardMatch es.Count 0 Then Return True Else Return False End If End Function
Jul 26 '06 #2
[I'm not actually going to directly answer your question]

Chris wrote:
Hi everyone,

I'm trying to parse through the contents of some text files with regular
expressions, but am new to regular expressions and how to use them in
VB.net.

I'm pretty sure that the regular expressions are correct as I got them from
regexlib.com and tested them in the Regulator and Expresso.

The problem is I tested this function with a file that contains a string
which should be seen by the SSNRegex. This makes me think that something is
definitely wrong in my program.
[snip]
''' U.S. social security numbers (SSN), within the range of numbers
''' that have been currently allocated. Matches the pattern AAA-GG-SSSS,
''' AAA GG SSSS, AAA-GG SSSS, AAA GG-SSSS, AAAGGSSSS, AAA-GGSSSS,
AAAGG-SSSS,
''' AAAGG SSSS or AAA GGSSSS. All zero in any one field is not allowed.
'''** Additionally, spaces and/or dashes and/or nothing are allowed.
Use String.Replace to remove spaces and hyphens
Check that the resulting string regex-matches ^\d{9}$
and doesn't match ^000 or ^...00 or 0000$

^^ readable, maintainable
''' Thanks to Joe Johnston and Regexlib.com for this Regex
''' </summary>
''' <remarks></remarks>
Dim ssnRegex As String = "^(?!000)([0-6]\d{2}|7([0-6]\d|7[012])) ([ -])?
(?!00)\d\d([ -|])? (?!0000)\d{4}$"
^^ less so?
''' Matches major credit cards including: Visa (length 16, prefix 4);
''' Mastercard (length 16, prefix 51-55);
''' Diners Club/Carte Blanche (length 14, prefix 36, 38, or 300-305);
''' Discover (length 16, prefix 6011); American Express (length 15,
prefix 34 or 37).
''' Saves the card type as a named group to facilitate further
validation against a "card type";
''' checkbox in a program. All 16 digit formats are grouped 4-4-4-4
with an optional hyphen or
''' space between each group of 4 digits. The American Express format is
grouped 4-6-5 with an
''' optional hyphen or space between each group of digits. Formatting
characters must be consistant,
''' i.e. if two groups are separated by a hyphen, all groups must be
separated by a hyphen for a
''' match to occur.
Use String.Replace to remove spaces and hyphens
Check that the resulting string regex-matches ^\d{15}\d?$
Have a utility function that checks for prefixes and returns an
enumerated card type

^^ readable, maintainable
Thanks to Steven Smith and Regexlib.com for this
Regex
''' </summary>
''' <remarks></remarks>
Dim creditCardRegex As String =
"^(?:(?<Visa>4\ d{3})|(?<Master card>5[1-5]\d{2})|(?<Disco ver>6011)|(?<Di nersClub>(?:3[68]\d{2})|(?:30[0-5]\d))|(?<America nExpress>3[47]\d{2}))([
-]?)(?(DinersClub )(?:\d{6}\1\d{4 })|(?(AmericanE xpress)(?:\d{6} \1\d{5})|(?:\d{ 4}\1\d{4}\1\d{4 })))$" Dim options As System.Text.Reg ularExpressions .RegexOptions = _ (System.Text.Re gularExpression s.RegexOptions. IgnorePatternWh itespaceOr _ System.Text.Reg ularExpressions .RegexOptions.S ingleline Or _ System.Text.Reg ularExpressions .RegexOptions.C ompiled Or _ System.Text.Reg ularExpressions .RegexOptions.I gnoreCase) Dim ssnRegex As New Regex(RegExType s.ssnRegex, RegExTypes.opti ons) Dim creditCardRegex As New Regex(RegExType s.creditCardReg ex,RegExTypes.o ptions) Public Function CheckContents(B yVal Filename As String, ByRefFileConten ts As String) As Boolean '''''Check File Contents Against Regex''''' 'Not sure if this is correct. Dim ssnMatches As MatchCollection =ssnRegex.Match es(FileContents ) Dim creditCardMatch es As MatchCollection =creditCardRege x.Matches(FileC ontents) '''''Process any Matche
s''''' 'SSN matches For Each match As Match In ssnMatches Dim newFoundItem As New foundItem newFoundItem.fi leName = Filename newFoundItem.Ty peOfAsset = SSN foundItemsArray .Add(newFoundIt em) Next 'Credit Card matches For Each match As Match In creditCardMatch es 'Create a New Found Item Dim newFoundItem As New foundItem 'foundItem is just astruct in another file 'Set the File location newFoundItem.fi leName = Filename'Here I'm trying to capture the named grouped from the regex. Not sure ifthis is correct. 'Determine the CreditCard type by Regex match group Select Case True Case "Visa" = match.Groups.It em("Visa").Valu e newFoundItem.Ty peOfAsset = VISA Case "Mastercard " =match.Groups.I tem("Mastercard ").Value
newFoundItem.Ty peOfAsset = MASTERCARD Case "DinersClub " =match.Groups.I tem("DinersClub ").Value newFoundItem.Ty peOfAsset = DINERS_CLUB Case "AmericanExpres s" =match.Groups.I tem("AmericanEx press").Value newFoundItem.Ty peOfAsset = AMERICAN_EXPRES S Case Else newFoundItem.Ty peOfAsset = CREDITCARD End Select 'Add the newFoundItem to our array foundItemsArray .Add(newFoundIt em) Next If ssnMatches.Coun t 0 Or creditCardMatch es.Count 0 Then Return True Else Return False End If End Function

^^ less so?
--
Larry Lard
la*******@googl email.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Jul 27 '06 #3
Hi Chris,

I'm using OrchidGrid from SpringSys to parse and import data from text
files. It can parse data from delimited file, fix-length file or text that
has some pattern. If you have interest, could try to see if it can helps or
not. Could find it at http://www.springsys.com

-jeff

Hi everyone,

I'm trying to parse through the contents of some text files with regular
expressions, but am new to regular expressions and how to use them in
VB.net.

I'm pretty sure that the regular expressions are correct as I got them
from regexlib.com and tested them in the Regulator and Expresso.

The problem is I tested this function with a file that contains a string
which should be seen by the SSNRegex. This makes me think that something
is definitely wrong in my program.

Any help would be awesome.

Thanks in advance.

Chris

Code to follow:

Imports System.Text.Reg ularExpressions
''' <summary>
''' U.S. social security numbers (SSN), within the range of numbers
''' that have been currently allocated. Matches the pattern
AAA-GG-SSSS,
''' AAA GG SSSS, AAA-GG SSSS, AAA GG-SSSS, AAAGGSSSS, AAA-GGSSSS,
AAAGG-SSSS,
''' AAAGG SSSS or AAA GGSSSS. All zero in any one field is not allowed.
'''** Additionally, spaces and/or dashes and/or nothing are allowed.
''' Thanks to Joe Johnston and Regexlib.com for this Regex
''' </summary>
''' <remarks></remarks>
Dim ssnRegex As String = "^(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))
([ -])? (?!00)\d\d([ -|])? (?!0000)\d{4}$"
''' <summary>
''' Matches major credit cards including: Visa (length 16, prefix 4);
''' Mastercard (length 16, prefix 51-55);
''' Diners Club/Carte Blanche (length 14, prefix 36, 38, or 300-305);
''' Discover (length 16, prefix 6011); American Express (length 15,
prefix 34 or 37).
''' Saves the card type as a named group to facilitate further
validation against a "card type";
''' checkbox in a program. All 16 digit formats are grouped 4-4-4-4
with an optional hyphen or
''' space between each group of 4 digits. The American Express format
is grouped 4-6-5 with an
''' optional hyphen or space between each group of digits. Formatting
characters must be consistant,
''' i.e. if two groups are separated by a hyphen, all groups must be
separated by a hyphen for a
''' match to occur. Thanks to Steven Smith and Regexlib.com for this
Regex
''' </summary>
''' <remarks></remarks>
Dim creditCardRegex As String =
"^(?:(?<Visa>4\ d{3})|(?<Master card>5[1-5]\d{2})|(?<Disco ver>6011)|(?<Di nersClub>(?:3[68]\d{2})|(?:30[0-5]\d))|(?<America nExpress>3[47]\d{2}))([
-]?)(?(DinersClub )(?:\d{6}\1\d{4 })|(?(AmericanE xpress)(?:\d{6} \1\d{5})|(?:\d{ 4}\1\d{4}\1\d{4 })))$"Dim options As System.Text.Reg ularExpressions .RegexOptions = _(System.Text.R egularExpressio ns.RegexOptions .IgnorePatternW hitespaceOr _System.Text.Re gularExpression s.RegexOptions. Singleline Or _System.Text.Re gularExpression s.RegexOptions. Compiled Or _System.Text.Re gularExpression s.RegexOptions. IgnoreCase) Dim ssnRegex AsNew Regex(RegExType s.ssnRegex, RegExTypes.opti ons) Dim creditCardRegex AsNew Regex(RegExType s.creditCardReg ex,RegExTypes.o ptions) Public FunctionCheckCo ntents(ByVal Filename As String, ByRefFileConten ts As String) AsBoolean '''''Check File Contents Against Regex''''''Not sure if this is correct. Dim ssnMatches As MatchCollection =ssnRegex.Match es(FileContents ) Dim creditCardMatch es AsMatchCollecti on =creditCardRege x.Matches(FileC ontents)'''''Pr ocess any Matches''''' 'SSN matches For Eachmatch As Match In ssnMatches Dim newFoundItem As NewfoundItem newFoundItem.fi leName = FilenamenewFoun dItem.TypeOfAss et = SSNfoundItemsAr ray.Add(newFoun dItem) Next 'Credit Cardmatches For Each match As Match In creditCardMatch es'Create a New Found Item Dim newFoundItem As New foundItem'found Item is just astruct in another file 'Set the Filelocation newFoundItem.fi leName = Filename'Here I'm trying tocapture the named grouped from the regex. Not sure ifthis is correct.'Determ ine the CreditCard type by Regex match group SelectCase True Case "Visa" = match.Groups.It em("Visa").Valu enewFoundItem.T ypeOfAsset = VISA Case "Mastercard"=ma tch.Groups.Item ("Mastercard"). ValuenewFoundIt em.TypeOfAsset = MASTERCARD Case "DinersClub"=ma tch.Groups.Item ("DinersClub"). ValuenewFoundIt em.TypeOfAsset = DINERS_CLUB Case"AmericanEx press" =match.Groups.I tem("AmericanEx press").Valuene wFoundItem.Type OfAsset = AMERICAN_EXPRES S Case ElsenewFoundIte m.TypeOfAsset = CREDITCARD End Select'Add the newFoundItem to our arrayfoundItems Array.Add(newFo undItem) Next IfssnMatches.Co unt 0 Or creditCardMatch es.Count 0 ThenReturn True Else Return False End IfEnd Function>
Jul 29 '06 #4

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

Similar topics

7
2595
by: YoBro | last post by:
Hi I have used some of this code from the PHP manual, but I am bloody hopeless with regular expressions. Was hoping somebody could offer a hand. The output of this will put the name of a form field beside name. I want to get the following but not sure how to modify the code below. 1. Field Name (to appear beside NAME:) 2. Field Type (to appear beside TYPE:)
11
3902
by: Martin Robins | last post by:
I am trying to parse a string that is similar in form to an OLEDB connection string using regular expressions; in principle it is working, but certain character combinations in the string being parsed can completely wreck it. The string I am trying to parse is as follows: commandText=insert into (Text) values (@message + N': ' + @category);commandType=StoredProcedure; message=@message; category=@category I am looking to retrive name value...
12
8717
by: Simone Mehta | last post by:
hi All, I am parsing a CSV file. I want to read every row into a char array of reasonable size and then extract strings from it. <snippet> char foo="hello,world,bye,bye,world"; ..... sscanf(foo,"%s%*%s%*%s%*%s%*%s",s1,s2,s3,s4,s5); <snippet/> This is giving me junk .
2
2151
by: neilmcguigan | last post by:
this is more of a text parsing/regex kind of question, but i figured i'd start here. please let me know if this should go somewhere else. I'd like to implement google-like search syntax, a la http://www.google.ca/help/refinesearch.html so a text query like this: ("google search" "regular expressions") OR (syntax text) aSpecificField:somevalue
7
2331
by: M | last post by:
Hi, I need to parse text files to extract data records. The files will consist of a header, zero or more data records, and a trailer. I can discard the header and trailer but I must split the data records up and return them to an application. The complexity here is that I won't know the exact format of the files until run time. The files may or may not contain headers and trailers
1
2425
by: yonido | last post by:
hello, my goal is to get patterns out of email files - say "message forwarding" patterns (message forwarded from: xx to: yy subject: zz) now lets say there are tons of these patterns (by gmail, outlook, etc) - and i want to create some rules of how to get them out of the mail's html body. so at first i tried using regular expressions: for example - "any pattern that starts with a <p> and contains "from:"..." etc.
17
2784
by: Mark | last post by:
I must create a routine that finds tokens in small, arbitrary VB code snippets. For example, it might have to find all occurrences of {Formula} I was thinking that using regular expressions might be a neat way to solve this, but I am new to them. Can anyone give me a hint here? The catch is, it must only find tokens that are not quoted and not commented; examples follow
1
1763
by: Robert Neville | last post by:
Basically, I want to create a table in html, xml, or xslt; with any number of regular expressions; a script (Perl or Python) which reads each table row (regex and replacement); and performs the replacement on any file name, folder, or text file (e.g. css, php, html). For example, I often rename my mp3 (files); the folder holding the mp3 files; and replace these renamed values in a playlist/m3u/xml file. The table should hold clean...
5
3996
by: Svenn Are Bjerkem | last post by:
On Jul 23, 1:03 pm, christopher.saun...@durham.ac.uk (c d saunter) wrote: As a start I want to parse VHDL which is going to be synthesised, and I am limiting myself to the entities and the structural component placement. I will drop the processes and the concurrent assignments even if that will mask important information. It is a design viewer tool, not a design tool that I am writing. Xilinx ISE do give me the opportunity to browse my...
0
8709
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8952
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8909
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7791
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6555
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4649
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2371
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2018
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.