简体   繁体   中英

Regular expression to return full file name and path

I'm a bit rusty when it comes to regular expressions so I could really use some expert help for the syntax. I'm looking for a regular expression that will return the full file name and path from a string. I am using the reference "Microsoft VBScript Regular Expressions 5.5" for Excel 2010 VBA. I just need the regex string.

Here's an example of what I'm working on. If the string is

=VLOOKUP($X18, 'E:\\BUDGET 2012-13\\Round 2 - final\\program worksheets[AD allocations Support 2012 R2.xlsx]2013'!costcenter, Y$5+2, FALSE)

then the returned value would be

'E:\\BUDGET 2012-13\\Round 2 - final\\program worksheets[AD allocations Support 2012 R2.xlsx]2013'

OR

'E:\\BUDGET 2012-13\\Round 2 - final\\program worksheets[AD allocations Support 2012 R2.xlsx]

( I can code around either return value ). Thank you!

-- DOH! --

I figured it out a few minutes ago. Being a newb I can't answer my own question so I'm doing it here -- some of the rules here are odd...anyway... The syntax is

'.+?'

and will return

'E:\\BUDGET 2012-13\\Round 2 - final\\program worksheets[AD allocations Support 2012 R2.xlsx]2013'

If you know of a better way please feel free to post it.

copy from my regex toolbox:
'([a-zA-Z]:\\\\(?:[^\\\\/:*?"<>|#]++\\\\)*+)([^\\\\/:*?"<>|#]+)'
I have tested your data with http://regexr.com?31oaq , you will get path from group 1, file name from group 2. I hope this can help you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM