Getting last backslash in file path through regex

Set the file path, for example: \\ server \ folder_A \ folder_B \ etc \ more.mov

I need a regex that will give me the last backslash so that I can extract the actual file name.

My attempt "$ \\" returns nothing.

I am using coldfusion.

Suggestions...

+4
source share
3 answers

Do you just need everything after the last backslash (file name)?

([^\\]+)$

The file name will be contained in the capture.

To match the beginning with the last backslash, you would do ...

\\[^\\]+$

I am not familiar with coldfusion, but I assume that if it performs regular expressions, it also captures. If you really need a position and you can get it from the match, the second expression may be what you want.

(Edited for clarity and answer the question)

+4
source

What about

 <cfset fileName = GetFileFromPath("\\server\folder_A\folder_B\etc\more.mov") /> 
+7
source

Do you need to use regex? Why not break the line and grab the last item?

 <cfset fileName = ListLast(filePath, "\\")> 
+5
source

Source: https://habr.com/ru/post/1307184/


All Articles