如何使用jQuery从字符串中删除“-”

时间:2018-10-17 05:56:09

标签: javascript jquery

如何从整个字符串中删除“-”?

我正在使用此行,但仅对第一个“-”有效,它不会删除其他“-”。

图片名称:cropped-Journal-trend-02.png

word1 AND word2 AND word4

3 个答案:

答案 0 :(得分:1)

您可以添加全局的g修饰符。第一次匹配后不会返回

imagePath: $(this).find('td:eq(3)').html().replace(/-/g, '')

答案 1 :(得分:1)

imagePath: $(this).find('td:eq(3)').html().replace(/-/g, '')

答案 2 :(得分:0)

var imagePath = "cropped-Journal-trend-02.png";
var newImagepath = imagePath.replace(new RegExp('-', 'g'),"");

可以请您尝试一下。它将删除所有-从您的字符串中