假设现有一地址:
let url = "http://www.bilibili.com/yellowbooks.pdf";;
提取文件名(含后缀):
let fileName = url.match(/[^\/]+\.[^\/]+$/)[0]; //"yellowbooks.pdf"
提取文件名(不含后缀):
let _fileName = fileName.replace(/\.(\w+)$/, ''); //"yellowbooks"
提取文件后缀:
let fileEx = fileName.replace(/.+\./, ''); //"pdf"
提取文件所在地址:
let fileAdd = url.replace(fileName, ''); //"http://www.bilibili.com/";
wxs写法
<wxs module="wxs">
var getThumbnail = function (path, px) {
var reg = getRegExp('[^\/]+\.[^\/]+$')
var fileName = path.match(reg).toString()
var fileDir = path.replace(fileName, '')
var thumbnail = fileDir + 'thumbnail' + px.toString() + '/' + fileName
return thumbnail
};
module.exports = {
getThumbnail: getThumbnail
}
</wxs>