Need a regex pattern to find a string between two strings

Hi
I am looking to get the customer's name  from a multi-page computer generated document.  In these documents, then name of the customer always follows the pattern shown below.  


1) Customer Information                  ----- (string constant)
2) Customer                                       ------ (string constant)
3) Customer Name                           ------ (information being sought)
4) Contact Telephone Number ----------  (string constant)

It actually looks like this in the document.  There is a line feed after each string constant  and customer name.

Customer Information
Customer
John Doe
Contact telephone number


There would only be one instance of a customer per document. Could someone help me with the regex pattern please.  

Thank you.
peispudAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try EDITED
Customer\n(.*)\nContact Telephone Number

Open in new window

REgards
1
peispudAuthor Commented:
Nope..  it didn't work for me.

Just in case, I will include the code.  Perhaps I've got something else wrong.

 Public Function ExtractTMIData(ByVal strXX As String) As Ticket()
    Dim reg As New regExp
'    reg.Pattern = "Customer Information\s+Customer"
    reg.Pattern = "Customer\n(.*)\nContact Telephone Number"
    reg.Global = True
    reg.IgnoreCase = True
    Dim Matches As MatchCollection
    Set Matches = reg.Execute(strXX)
End Function

Open in new window

0
Rgonzo1971Commented:
Maybe replace \n with \n\r
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Rgonzo1971Commented:
then try
 Public Function ExtractTMIData(ByVal strXX As String) As Ticket()
    Dim reg As New regExp
'    reg.Pattern = "Customer Information\s+Customer"
    reg.Pattern = "Customer\n\r(.*)\n\rContact Telephone Number"
    reg.Global = True
    reg.IgnoreCase = True
    Dim Matches As MatchCollection
    Set Matches = reg.Execute(strXX)
ExtractTMIData = Matches(0).SubMatches(0)
End Function

Open in new window

0
Rgonzo1971Commented:
Could you send a dummy file?
0
peispudAuthor Commented:
Nope.  

The last command
ExtractTMIData = Matches(0).SubMatches(0)

Open in new window

generated an error code.  
Even with this commented out,  I did not get the customer name.
0
peispudAuthor Commented:
Ok..  here is a file with the important information changed.

I need to extract "John Doe"
0
peispudAuthor Commented:
Oops... Here is the file
Test.docx
0
Rgonzo1971Commented:
then try
 Public Function ExtractTMIData(ByVal strXX As String) As String
    Dim reg As New regExp
'    reg.Pattern = "Customer Information\s+Customer"
     reg.Pattern = "Customer\r(.*?)\rContact telephone number"
    reg.Global = True
    reg.IgnoreCase = True
    Dim Matches As MatchCollection
    Set Matches = reg.Execute(strXX)
ExtractTMIData = Matches(0).SubMatches(0)
End Function

Open in new window

0
Dan CraciunIT ConsultantCommented:
RegexBuddy says this should work:

reg.Pattern  = "Customer\r?\n(.*)"

Open in new window


HTH,
Dan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dan CraciunIT ConsultantCommented:
Dim myMatch As Match
Dim myMatches As MatchCollection
Dim myRegExp As RegExp
Set myRegExp = New RegExp
myRegExp.Pattern = "Customer\r?\n(.*)"
Set myMatches = myRegExp.Execute(SubjectString)
For Each myMatch In myMatches
	'matched text: myMatch.Value
	'match start: myMatch.FirstIndex
	'match length: myMatch.Length
	'backreference n text: myMatch.SubMatches(n-1)
Next

Open in new window


This is for VB6.
0
peispudAuthor Commented:
Thank you both for your help.

This is awesome!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.