Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于从文件名中删除Wordpress图像大小的正则表达式或标准子字符串解决方案_Javascript_Regex_Substring - Fatal编程技术网

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“ 它并不总是相同的

我需要使用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“

它并不总是相同的路径,也不总是jpg,但需要删除的总是
-123x123


我最好为此做一个正则表达式(如果是的话,我需要什么模式?),还是应该去掉最后一个
-
后的结尾,然后去掉文件扩展名,然后用串联重建字符串?

使用
string.prototype.replace()
函数替换特定的正则表达式模式:

var imagePath=”http://localhost:8888/test/wp-content/uploads/2016/12/P1010050-700x525.jpg“,
replaced=imagePath.replace(/\-[^-]+(\.\w+$/,“$1”);
控制台日志(已替换)