[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

Regex Pattern Help

Hello - In the related question, the pattern is working perfectly, but I've discovered that the file path doesn't always begin with file://.  So I have been reading up on the regex patterns and the behavior of the metacharacters, but I am having a hard time figuring this out.

I think if someone could please provide the correct pattern I need, then looking at the previous pattern and this new pattern will be helpful in understanding how everything works.

The complete file path is going to be similar to one of the following...
file://C:\Users\Public\aLXE-Pricing\EverBank2\JacksonvilleRateSheet4-16-2009 (2).pdf
C:\Users\Public\aLXE-Pricing\EverBank2\JacksonvilleRateSheet4-16-2009 (2).pdf

I wanted to try to match "Jacksonville" because that will always be in the file path.

Thank you!

Set Regex = CreateObject("vbscript.regexp")
    Regex.Pattern = "(//|\\\\)[^\[Jacksonville].]+\.pdf"
    Regex.Global = True
           regitm = Regex.test(objMess.body)
              If regitm Then
               Set regm = Regex.Execute(objMess.body)
            Forms("frmPricingLoadExternal")!txtFileLoc = Right$(regm(0), Len(regm(0)) - InStr(regm(0), "//") - 1)
            Else
            MsgBox "Message not found", vbSystemModal
               End If

Open in new window

0
rsburge
Asked:
rsburge
  • 5
  • 3
2 Solutions
 
käµfm³d 👽Commented:
^(?:file://)?.+Jacksonville[^.]+\.pdf$
0
 
rsburgeAuthor Commented:
Thank you for your response.  This doesn't seem to be working.  The word "file" is not always going to be in the pattern I am searching for.  Should that be excluded?
0
 
käµfm³d 👽Commented:
The "(?:file://)" is marked optional due to the trailing "?".
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
käµfm³d 👽Commented:
You might need to take out the "^" and "$" from the beginning and end of the pattern string for you purposes.
0
 
käµfm³d 👽Commented:

Set regex = CreateObject("vbscript.regexp")
 
regex.Pattern = "(?:file://)?.+Jacksonville[^.]+\.pdf"
regex.Global = True
regitm = regex.test(objMess.body)
 
If regitm Then
    Set regm = regex.Execute(objMess.body)
    Forms("frmPricingLoadExternal")!txtFileLoc = Right$(regm(0), Len(regm(0)) - InStr(regm(0), "//") - 1)
Else
    MsgBox "Message not found", vbSystemModal
End If

Open in new window

0
 
rsburgeAuthor Commented:
Thank you!  This is working fine with one exception.

At this line...
Forms("frmPricingLoadExternal")!txtFileLoc = Right$(regm(0), Len(regm(0)) - InStr(regm(0), "c:") + 1)

I am getting this value...
C:\Users\Public\aLXE-Pricing\EverBank2\JacksonvilleRateSheet (2).pdf"C:\Users\Public\aLXE-Pricing\EverBank2\JacksonvilleRateSheet (2).pdf

Is this the result of the regex pattern or do I have something wrong with my Right function paramaters?

Thanks!
0
 
käµfm³d 👽Commented:
If you like, you can have the RegEx do the extracting for you by using grouping:

I put a set of parentheses around the text I want to capture -- .+Jacksonville[^.]+\.pdf

Then, in the execute portion, I check for the sub-match (or group) by checking the SubMatches property of the Match object
Set regex = CreateObject("vbscript.regexp")
Dim test As String
 
test = "C:\Users\Public\aLXE-Pricing\EverBank2\JacksonvilleRateSheet (2).pdf"
 
regex.Pattern = "(?:file://)?C:\\(.+Jacksonville[^.]+\.pdf)"
regex.Global = True
regitm = regex.test(test)
 
If regitm Then
    Set regm = regex.Execute(test)
    
    Forms("frmPricingLoadExternal")!txtFileLoc = regm(0).SubMatches(0)
Else
    MsgBox "Message not found", vbSystemModal
End If

Open in new window

0
 
rsburgeAuthor Commented:
Thank you for all of the information.  Works great!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now