Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the last backslash in a filepath via regex

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...?

like image 638
Anthony Avatar asked Apr 16 '10 20:04

Anthony


People also ask

How do you find backslash in regex?

To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).

How do I enable backslash in regex Java?

Backslash is an escape character in regular expressions. You can use '\\' to refer to a single backslash in a regular expression. However, backslash is also an escape character in Java literal strings. To make a regular expression from a string literal, you have to escape each of its backslashes.

What is double backslash in regex?

The backslash character ( \ ) is the escaping character. It can be used to denote an escaped character, a string, literal, or one of the set of supported special characters. Use a double backslash ( \\ ) to denote an escaped string literal.

What does backslash 1 mean in regex?

The backreference \1 (backslash one) references the first capturing group. \1 matches the exact same text that was matched by the first capturing group. The / before it is a literal character. It is simply the forward slash in the closing HTML tag that we are trying to match.


1 Answers

What about

<cfset fileName = GetFileFromPath("\\server\folder_A\folder_B\etc\more.mov") />
like image 126
Sergey Galashyn Avatar answered Sep 27 '22 22:09

Sergey Galashyn