问题描述
给出一个文件路径,例如:\\server\folder_A\folder_B\etc\more.mov
Given a file path such as: \\server\folder_A\folder_B\etc\more.mov
我需要一个正则表达式,请给我 last 反斜杠,以便提取实际的文件名。
I need a regex that'll give me the last backslash so I can extract the actual file name.
我尝试的 $ \\未返回任何内容。
My attempt of "$\\" is not returning anything.
我正在使用Coldfusion。
I'm using coldfusion.
建议...?
推荐答案
您是否只想要一切在最后一个反斜杠(文件名)之后?
Do you just want everything after the last backslash (the filename)?
([^ \\] +)$
文件名将包含在捕获中。
The filename will be contained in the capture.
要从最后一个反斜杠开始进行匹配。 。
To match starting at the last backslash you'd do...
\\ [^ \\] + $
我对Coldfusion不熟悉,但是我假设如果它执行正则表达式,那么它也会捕获。如果您确实需要该职位,并且可以从比赛中获得该职位,则第二个表达式可能就是您想要的。
I'm not familiar with coldfusion, but I'm assuming that if it does regular expressions, it does captures as well. If you do really need the position and can get that from the match, the second expression might be what you want.
(为清楚起见并进行评论编辑)
(Edited for clarity and to answer comment)
这篇关于通过正则表达式获取文件路径中的最后一个反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!