简体   繁体   English

正则表达式返回完整的文件名和路径

[英]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. 我正在为Excel 2010 VBA使用引用“ Microsoft VBScript正则表达式5.5”。 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) = VLOOKUP($ X18,'E:\\ BUDGET 2012-13 \\ Round 2-final \\ program worksheets [AD assignments 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' 'E:\\ BUDGET 2012-13 \\ Round 2-final \\ program工作表[AD分配支持2012 R2.xlsx] 2013'

OR 要么

'E:\\BUDGET 2012-13\\Round 2 - final\\program worksheets[AD allocations Support 2012 R2.xlsx] 'E:\\ BUDGET 2012-13 \\ Round 2-final \\ program工作表[AD分配支持2012 R2.xlsx]

( I can code around either return value ). (我可以围绕任一返回值进行编码)。 Thank you! 谢谢!

-- DOH! -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' 'E:\\ BUDGET 2012-13 \\ Round 2-final \\ program工作表[AD分配支持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 :) 我已经使用http://regexr.com?31oaq测试了您的数据,您将获得第1组的路径,第2组的文件名。希望对您有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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