私信  •  关注

MetalGodwin

MetalGodwin 最近创建的主题
MetalGodwin 最近回复了
11 年前
回复了 MetalGodwin 创建的主题 » regex使用验证器传递变量值并验证jquery[duplicate]
String.prototype.replaceAll = function(a, b) {
    return this.replace(new RegExp(a.replace(/([.?*+^$[\]\\(){}|-])/ig, "\\$1"), 'ig'), b)
}

像这样测试:

var whatever = 'Some [b]random[/b] text in a [b]sentence.[/b]'

console.log(whatever.replaceAll("[", "<").replaceAll("]", ">"))