Javascript 用于从文件名中删除Wordpress图像大小的正则表达式或标准子字符串解决方案
我需要使用Javascript从图像路径中删除Wordpress的宽度和高度细节,而不是从完整图像中删除。例如:Javascript 用于从文件名中删除Wordpress图像大小的正则表达式或标准子字符串解决方案,javascript,regex,substring,Javascript,Regex,Substring,我需要使用Javascript从图像路径中删除Wordpress的宽度和高度细节,而不是从完整图像中删除。例如: imagePath = "http://localhost:8888/test/wp-content/uploads/2016/12/P1010050-700x525.jpg" 我需要将imagePath转换为imagePath=”http://localhost:8888/test/wp-content/uploads/2016/12/P1010050.jpg“ 它并不总是相同的
imagePath = "http://localhost:8888/test/wp-content/uploads/2016/12/P1010050-700x525.jpg"
我需要将imagePath
转换为imagePath=”http://localhost:8888/test/wp-content/uploads/2016/12/P1010050.jpg“
它并不总是相同的路径,也不总是jpg,但需要删除的总是-123x123
我最好为此做一个正则表达式(如果是的话,我需要什么模式?),还是应该去掉最后一个
-
后的结尾,然后去掉文件扩展名,然后用串联重建字符串?使用string.prototype.replace()
函数替换特定的正则表达式模式:
var imagePath=”http://localhost:8888/test/wp-content/uploads/2016/12/P1010050-700x525.jpg“,
replaced=imagePath.replace(/\-[^-]+(\.\w+$/,“$1”);
控制台日志(已替换)代码>