Reputation: 742
Given a file path such as: \\server\folder_A\folder_B\etc\more.mov
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.
I'm using coldfusion.
Suggestions...?
Upvotes: 5
Views: 7879
Reputation: 6956
What about
<cfset fileName = GetFileFromPath("\\server\folder_A\folder_B\etc\more.mov") />
Upvotes: 7
Reputation: 2605
Do you absolutely have to use regex? Why not split the string and grab the last element?
<cfset fileName = ListLast(filePath, "\\")>
Upvotes: 5
Reputation: 76918
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...
\\[^\\]+$
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)
Upvotes: 6