Home All Groups Group Topic Archive Search About

Parsing Files with Regular Expressions

Author
26 Jul 2006 2:56 PM
Chris
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})|(?(AmericanExpress)(?:\d{6}\1\d{5})|(?:\d{4}\1\d{4}\1\d{4})))$"    Dim options As System.Text.RegularExpressions.RegexOptions = _       (System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespaceOr _       System.Text.RegularExpressions.RegexOptions.Singleline Or _       System.Text.RegularExpressions.RegexOptions.Compiled Or _       System.Text.RegularExpressions.RegexOptions.IgnoreCase)    Dim ssnRegex As New Regex(RegExTypes.ssnRegex, RegExTypes.options)    Dim creditCardRegex As New Regex(RegExTypes.creditCardRegex,RegExTypes.options)    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

Author
26 Jul 2006 3:47 PM
Chris
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})|(?(AmericanExpress)(?:\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.IgnorePatternWhitespace Or _
  34..        System.Text.RegularExpressions.RegexOptions.Singleline Or _
  35..        System.Text.RegularExpressions.RegexOptions.Compiled Or _
  36..        System.Text.RegularExpressions.RegexOptions.IgnoreCase)
  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


Show quoteHide quote
"Chris" <consult_Chris@nospam.yahoo.com> wrote in message news:uOml6OMsGHA.240@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})|(?(AmericanExpress)(?:\d{6}\1\d{5})|(?:\d{4}\1\d{4}\1\d{4})))$"    Dim options As System.Text.RegularExpressions.RegexOptions = _       (System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespaceOr _       System.Text.RegularExpressions.RegexOptions.Singleline Or _       System.Text.RegularExpressions.RegexOptions.Compiled Or _       System.Text.RegularExpressions.RegexOptions.IgnoreCase)    Dim ssnRegex As New Regex(RegExTypes.ssnRegex, RegExTypes.options)    Dim creditCardRegex As New Regex(RegExTypes.creditCardRegex,RegExTypes.options)    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
>
Author
27 Jul 2006 3:31 PM
Larry Lard
[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?

Show quoteHide quote
>     ''' 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})|(?(AmericanExpress)(?:\d{6}\1\d{5})|(?:\d{4}\1\d{4}\1\d{4})))$"    Dim options As System.Text.RegularExpressions.RegexOptions = _       (System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespaceOr _       System.Text.RegularExpressions.RegexOptions.Singleline Or _       System.Text.RegularExpressions.RegexOptions.Compiled Or _       System.Text.RegularExpressions.RegexOptions.IgnoreCase)    Dim ssnRegex As New Regex(RegExTypes.ssnRegex, RegExTypes.options)    Dim creditCardRegex As New Regex(RegExTypes.creditCardRegex,RegExTypes.options)    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
larryl***@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Author
29 Jul 2006 2:40 AM
Jeff Glatt
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




Show quoteHide quote
> 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})|(?(AmericanExpress)(?:\d{6}\1\d{5})|(?:\d{4}\1\d{4}\1\d{4})))$"Dim options As System.Text.RegularExpressions.RegexOptions = _(System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespaceOr _System.Text.RegularExpressions.RegexOptions.Singleline Or _System.Text.RegularExpressions.RegexOptions.Compiled Or _System.Text.RegularExpressions.RegexOptions.IgnoreCase)    Dim ssnRegex AsNew Regex(RegExTypes.ssnRegex, RegExTypes.options)    Dim creditCardRegex AsNew Regex(RegExTypes.creditCardRegex,RegExTypes.options)    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.TypeOfAsset = VISA                    Case "Mastercard"=match.Groups.Item("Mastercard").ValuenewFoundItem.TypeOfAsset = MASTERCARD                    Case "DinersClub"=match.Groups.Item("DinersClub").ValuenewFoundItem.TypeOfAsset = DINERS_CLUB                    Case"AmericanExpress" =match.Groups.Item("AmericanExpress").ValuenewFoundItem.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>