无法用regexp替换所有出现的字符,直到唯一字符?

时间:2018-03-14 08:54:13

标签: javascript regex

如果字符串以/开头直到下一个唯一字符,我想替换...我尝试过如下,但它只将所有事件替换成一个!我想替换所有出现的字符......



var textTitle = "///test///";
var result = textTitle.replace(/^\/{1,}/g, '../');
console.log(result); // wanted => ../../../test///

textTitle = "//test/";
result = textTitle.replace(/^\/{1,}/g, '../');
console.log(result); // wanted => ../../test/




2 个答案:

答案 0 :(得分:1)

使用abp.multiTenancy.isEnabled 标志,对y属性的每个成功方法采取一步:



lastIndex




答案 1 :(得分:0)

你可以尝试:

var textTitle = "///test///";
var result = textTitle.replace(/^\/{1,}/g, (match, key) => {
    return match.split('').reduce((res, next) => res += '..' + next, '');

});
console.log(result);

var textTitle = "///test///";
    var result = textTitle.replace(/^\/{1,}/g, (match, key) => {
        return match.split('').reduce((res, next) => res += '..' + next, '');

    });
    console.log(result);