SoFunction
Updated on 2025-04-09

Use regularity to get the name of the specified path file

It mainly involves the special characters of "\" in javascript. Should regular expressions be used?
<script>
var m="D:\Picture\Beggar Gang.jpg"
//Solve Solve
</script>
I hope the value I can get is "Beggars' Sect"
Copy the codeThe code is as follows:

<script type="text/javascript">
var s ="D:\\Picture\\Beggar Gang.jpg";
var t = (/\\([^\\^.]+)\.[^\\]*$/)[1];
alert(t);
</script>