troubleshooting Question

Regex - Capture everything between two strings.

Avatar of peispud
peispudFlag for Canada asked on
Regular Expressions
8 Comments1 Solution726 ViewsLast Modified:

 The code below does not work properly.  I am using Microsoft Access VBA.   When the code works properly,  the variable
 strAnswer  =  "Line 4:Line5" with the nonprinting characters preserved.

I am using the wrong pattern.  Also, I am not sure how to assign the regex result to a string.

I would appreciate your help.

Public Sub ExtractString()
    Dim str As String
    str = "Line 1." & vbCrLf
    str = str & "Line 2 :" & vbCrLf
    str = str & "Line 3 :" & vbCrLf
    str = str & "Line 4:" & vbCrLf
    str = str & "Line 5:" & vbCrLf
    str = str & "Line 6:" & vbCrLf
    str = str & "The End"
    Dim reg As New regExp
    reg.Pattern = "Line 4:\r(.*?)\rLine 6:"
    reg.Global = True
    reg.IgnoreCase = True
    Dim Matches As MatchCollection
    Set Matches = reg.Execute(str)
    Dim strAnswer As String
    strAnswer = reg.Execute(str)
End Sub

Thank you.
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros