473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.RegularExpressions
''' <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})|(?<Mastercard>5[1-5]\d{2})|(?<Discover>6011)|(?<DinersClub>(?:3[68]\d{2})|(?:30[0-5]\d))|(?<AmericanExpress>3[47]\d{2}))([
-]?)(?(DinersClub)(?:\d{6}\1\d{4})|(?(AmericanExpres s)(?:\d{6}\1\d{5})|(?:\d{4}\1\d{4}\1\d{4})))$" Dim options As System.Text.RegularExpressions.RegexOptions = _ (System.Text.RegularExpressions.RegexOptions.Ignor ePatternWhitespaceOr _ System.Text.RegularExpressions.RegexOptions.Single line Or _ System.Text.RegularExpressions.RegexOptions.Compil ed Or _ System.Text.RegularExpressions.RegexOptions.Ignore Case) Dim ssnRegex As New Regex(RegExTypes.ssnRegex, RegExTypes.options) Dim creditCardRegex As New Regex(RegExTypes.creditCardRegex,RegExTypes.option s) Public Function CheckContents(ByVal Filename As String, ByRefFileContents As String) As Boolean '''''Check File Contents Against Regex''''' 'Not sure if this is correct. Dim ssnMatches As MatchCollection =ssnRegex.Matches(FileContents) Dim creditCardMatches As MatchCollection =creditCardRegex.Matches(FileContents) '''''Process any Matches''''' 'SSN matches For Each match As Match In ssnMatches Dim newFoundItem As New foundItem newFoundItem.fileName = Filename newFoundItem.TypeOfAsset = SSN foundItemsArray.Add(newFoundItem) Next 'Credit Card matches For Each match As Match In creditCardMatches 'Create a New Found Item Dim newFoundItem As New foundItem 'foundItem is just astruct in another file 'Set the File location newFoundItem.fileName = 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.Item("Visa").Value newFoundItem.TypeOfAsset = VISA Case "Mastercard" =match.Groups.Item("Mastercard").Value newFoundItem.TypeOfAsset = MASTERCARD Case "DinersClub" =match.Groups.Item("DinersClub").Value newFoundItem.TypeOfAsset = DINERS_CLUB Case "AmericanExpress" =match.Groups.Item("AmericanExpress").Value newFoundItem.TypeOfAsset = AMERICAN_EXPRESS Case Else newFoundItem.TypeOfAsset = CREDITCARD End Select 'Add the newFoundItem to our array foundItemsArray.Add(newFoundItem) Next If ssnMatches.Count 0 Or creditCardMatches.Count 0 Then Return True Else Return False End If End Function

Jul 26 '06 #1
3 2507
Here is a more readable version of the code.
1.. Imports System.Text.RegularExpressions
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})|(?<Mastercard>5[1-5]\d{2})|(?<Discover>6011)|(?<DinersClub>(?:3[68]\d{2})|(?:30[0-5]\d))|(?<AmericanExpress>3[47]\d{2}))([ -]?)(?(DinersClub)(?:\d{6}\1\d{4})|(?(AmericanExpres s)(?:\d{6}\1\d{5})|(?:\d{4}\1\d{4}\1\d{4})))$"
30..
31..
32.. Dim options As System.Text.RegularExpressions.RegexOptions = _
33.. (System.Text.RegularExpressions.RegexOptions.Ignor ePatternWhitespace Or _
34.. System.Text.RegularExpressions.RegexOptions.Single line Or _
35.. System.Text.RegularExpressions.RegexOptions.Compil ed Or _
36.. System.Text.RegularExpressions.RegexOptions.Ignore Case)
37..
38..
39.. Dim ssnRegex As New Regex(RegExTypes.ssnRegex, RegExTypes.options)
40.. Dim creditCardRegex As New Regex(RegExTypes.creditCardRegex, RegExTypes.options)
41..
42..
43.. Public Function CheckContents(ByVal Filename As String, ByRef FileContents As String) As Boolean
44..
45..
46.. '''''Check File Contents Against Regex'''''
47.. 'Dim matches As MatchCollection = Regex.Matches(inputString,regex,regexOptions)
48.. Dim ssnMatches As MatchCollection = ssnRegex.Matches(FileContents)
49.. Dim creditCardMatches As MatchCollection = creditCardRegex.Matches(FileContents)
50..
51.. '''''Process any Matches'''''
52.. 'SSN matches
53.. For Each match As Match In ssnMatches
54.. Dim newFoundItem As New foundItem
55.. newFoundItem.fileName = Filename
56.. newFoundItem.TypeOfAsset = SSN
57.. foundItemsArray.Add(newFoundItem)
58.. Next
59..
60.. 'Credit Card matches
61.. For Each match As Match In creditCardMatches
62.. 'Create a New Found Item
63.. Dim newFoundItem As New foundItem
64.. 'Set the File location
65.. newFoundItem.fileName = Filename
66..
67.. 'Determine the CreditCard type by Regex match group
68.. Select Case True
69.. Case "Visa" = match.Groups.Item("Visa").Value
70.. newFoundItem.TypeOfAsset = VISA
71.. Case "Mastercard" = match.Groups.Item("Mastercard").Value
72.. newFoundItem.TypeOfAsset = MASTERCARD
73.. Case "DinersClub" = match.Groups.Item("DinersClub").Value
74.. newFoundItem.TypeOfAsset = DINERS_CLUB
75.. Case "AmericanExpress" = match.Groups.Item("AmericanExpress").Value
76.. newFoundItem.TypeOfAsset = AMERICAN_EXPRESS
77.. Case Else
78.. newFoundItem.TypeOfAsset = CREDITCARD
79.. End Select
80.. 'Add the newFoundItem to our array
81.. foundItemsArray.Add(newFoundItem)
82..
83.. Next
84..
85.. If ssnMatches.Count 0 Or creditCardMatches.Count 0 Then
86.. Return True
87.. Else
88.. Return False
89.. End If
90..
91.. End Function
"Chris" <co***********@nospam.yahoo.comwrote in message news:uO*************@TK2MSFTNGP02.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.RegularExpressions
''' <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})|(?<Mastercard>5[1-5]\d{2})|(?<Discover>6011)|(?<DinersClub>(?:3[68]\d{2})|(?:30[0-5]\d))|(?<AmericanExpress>3[47]\d{2}))([
-]?)(?(DinersClub)(?:\d{6}\1\d{4})|(?(AmericanExpres s)(?:\d{6}\1\d{5})|(?:\d{4}\1\d{4}\1\d{4})))$" Dim options As System.Text.RegularExpressions.RegexOptions = _ (System.Text.RegularExpressions.RegexOptions.Ignor ePatternWhitespaceOr _ System.Text.RegularExpressions.RegexOptions.Single line Or _ System.Text.RegularExpressions.RegexOptions.Compil ed Or _ System.Text.RegularExpressions.RegexOptions.Ignore Case) Dim ssnRegex As New Regex(RegExTypes.ssnRegex, RegExTypes.options) Dim creditCardRegex As New Regex(RegExTypes.creditCardRegex,RegExTypes.option s) Public Function CheckContents(ByVal Filename As String, ByRefFileContents As String) As Boolean '''''Check File Contents Against Regex''''' 'Not sure if this is correct. Dim ssnMatches As MatchCollection =ssnRegex.Matches(FileContents) Dim creditCardMatches As MatchCollection =creditCardRegex.Matches(FileContents) '''''Process any Matches''''' 'SSN matches For Each match As Match In ssnMatches Dim newFoundItem As New foundItem newFoundItem.fileName = Filename newFoundItem.TypeOfAsset = SSN foundItemsArray.Add(newFoundItem) Next 'Credit Card matches For Each match As Match In creditCardMatches 'Create a New Found Item Dim newFoundItem As New foundItem 'foundItem is just astruct in another file 'Set the File location newFoundItem.fileName = 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.Item("Visa").Value newFoundItem.TypeOfAsset = VISA Case "Mastercard" =match.Groups.Item("Mastercard").Value newFoundItem.TypeOfAsset = MASTERCARD Case "DinersClub" =match.Groups.Item("DinersClub").Value newFoundItem.TypeOfAsset = DINERS_CLUB Case "AmericanExpress" =match.Groups.Item("AmericanExpress").Value newFoundItem.TypeOfAsset = AMERICAN_EXPRESS Case Else newFoundItem.TypeOfAsset = CREDITCARD End Select 'Add the newFoundItem to our array foundItemsArray.Add(newFoundItem) Next If ssnMatches.Count 0 Or creditCardMatches.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})|(?<Mastercard>5[1-5]\d{2})|(?<Discover>6011)|(?<DinersClub>(?:3[68]\d{2})|(?:30[0-5]\d))|(?<AmericanExpress>3[47]\d{2}))([
-]?)(?(DinersClub)(?:\d{6}\1\d{4})|(?(AmericanExpres s)(?:\d{6}\1\d{5})|(?:\d{4}\1\d{4}\1\d{4})))$" Dim options As System.Text.RegularExpressions.RegexOptions = _ (System.Text.RegularExpressions.RegexOptions.Ignor ePatternWhitespaceOr _ System.Text.RegularExpressions.RegexOptions.Single line Or _ System.Text.RegularExpressions.RegexOptions.Compil ed Or _ System.Text.RegularExpressions.RegexOptions.Ignore Case) Dim ssnRegex As New Regex(RegExTypes.ssnRegex, RegExTypes.options) Dim creditCardRegex As New Regex(RegExTypes.creditCardRegex,RegExTypes.option s) Public Function CheckContents(ByVal Filename As String, ByRefFileContents As String) As Boolean '''''Check File Contents Against Regex''''' 'Not sure if this is correct. Dim ssnMatches As MatchCollection =ssnRegex.Matches(FileContents) Dim creditCardMatches As MatchCollection =creditCardRegex.Matches(FileContents) '''''Process any Matche
s''''' 'SSN matches For Each match As Match In ssnMatches Dim newFoundItem As New foundItem newFoundItem.fileName = Filename newFoundItem.TypeOfAsset = SSN foundItemsArray.Add(newFoundItem) Next 'Credit Card matches For Each match As Match In creditCardMatches 'Create a New Found Item Dim newFoundItem As New foundItem 'foundItem is just astruct in another file 'Set the File location newFoundItem.fileName = 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.Item("Visa").Value newFoundItem.TypeOfAsset = VISA Case "Mastercard" =match.Groups.Item("Mastercard").Value
newFoundItem.TypeOfAsset = MASTERCARD Case "DinersClub" =match.Groups.Item("DinersClub").Value newFoundItem.TypeOfAsset = DINERS_CLUB Case "AmericanExpress" =match.Groups.Item("AmericanExpress").Value newFoundItem.TypeOfAsset = AMERICAN_EXPRESS Case Else newFoundItem.TypeOfAsset = CREDITCARD End Select 'Add the newFoundItem to our array foundItemsArray.Add(newFoundItem) Next If ssnMatches.Count 0 Or creditCardMatches.Count 0 Then Return True Else Return False End If End Function

^^ less so?
--
Larry Lard
la*******@googlemail.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.RegularExpressions
''' <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})|(?<Mastercard>5[1-5]\d{2})|(?<Discover>6011)|(?<DinersClub>(?:3[68]\d{2})|(?:30[0-5]\d))|(?<AmericanExpress>3[47]\d{2}))([
-]?)(?(DinersClub)(?:\d{6}\1\d{4})|(?(AmericanExpres s)(?:\d{6}\1\d{5})|(?:\d{4}\1\d{4}\1\d{4})))$"Dim options As System.Text.RegularExpressions.RegexOptions = _(System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespaceOr _System.Text.RegularExpressions.RegexOptions.Singl eline Or _System.Text.RegularExpressions.RegexOptions.Compi led Or _System.Text.RegularExpressions.RegexOptions.Ignor eCase) Dim ssnRegex AsNew Regex(RegExTypes.ssnRegex, RegExTypes.options) Dim creditCardRegex AsNew Regex(RegExTypes.creditCardRegex,RegExTypes.option s) Public FunctionCheckContents(ByVal Filename As String, ByRefFileContents As String) AsBoolean '''''Check File Contents Against Regex''''''Not sure if this is correct. Dim ssnMatches As MatchCollection=ssnRegex.Matches(FileContents) Dim creditCardMatches AsMatchCollection =creditCardRegex.Matches(FileContents)'''''Process any Matches''''' 'SSN matches For Eachmatch As Match In ssnMatches Dim newFoundItem As NewfoundItem newFoundItem.fileName = FilenamenewFoundItem.TypeOfAsset = SSNfoundItemsArray.Add(newFoundItem) Next 'Credit Cardmatches For Each match As Match In creditCardMatches'Create a New Found Item Dim newFoundItem As New foundItem'foundItem is just astruct in another file 'Set the Filelocation newFoundItem.fileName = Filename'Here I'm trying tocapture the named grouped from the regex. Not sure ifthis is correct.'Determine the CreditCard type by Regex match group SelectCase True Case "Visa" = match.Groups.Item("Visa").ValuenewFoundItem.TypeOf Asset = VISA Case "Mastercard"=match.Groups.Item("Mastercard").Value newFoundItem.TypeOfAsset = MASTERCARD Case "DinersClub"=match.Groups.Item("DinersClub").Value newFoundItem.TypeOfAsset = DINERS_CLUB Case"AmericanExpress" =match.Groups.Item("AmericanExpress").ValuenewFoun dItem.TypeOfAsset = AMERICAN_EXPRESS Case ElsenewFoundItem.TypeOfAsset = CREDITCARD End Select'Add the newFoundItem to our arrayfoundItemsArray.Add(newFoundItem) Next IfssnMatches.Count 0 Or creditCardMatches.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
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...
11
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...
12
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"; ........
2
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...
7
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...
1
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,...
17
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...
1
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...
5
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.