日期:2014-05-16 浏览次数:20424 次
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> </head> <body> <div id="test"> D:\eclipse\apache-tomcat-7.0.23\webapps\LastProject\uploads\20125914035913.jpg </div> <script> function $(el){ return typeof el == 'string' ? document.getElementById(el) : el; } var s = $('test').innerHTML; var r = /uploads\\\d+\.jpg/; alert(s.match(r)) </script> </body> </html>
------解决方案--------------------
var str = 'D:\\eclipse\\apache-tomcat-7.0.23\\webapps\\LastProject\\uploads\\20125914035913.jpg'; var ar = str.split('\\'); var result = ar[ar.length - 2] + '\\' + ar[ar.length - 1]; alert(result);