我有以下字符串
(Very strong=="Very strong"?100:(Very strong=="Above Average"?75:(Very strong=="Average"?50:(Very strong=="Below Average"?25:(Very strong=="Cannot determine"?0:(Very strong=="Poor"?0:0))))))
我的愿望是
("Very strong"=="Very strong"?100:("Very strong"=="Above Average"?75:("Very strong"=="Average"?50:("Very strong"=="Below Average"?25:("Very strong"=="Cannot determine"?0:("Very strong"=="Poor"?0:0))))))
我如何附加双引号?未添加双引号。
由于
答案 0 :(得分:1)
看起来很奇怪你需要这样做,但是如果结构总是一样的话,这是一个非常简单的reg exp。
var str = '(Very strong=="Very strong"?100:(Very strong=="Above Average"?75:(Very strong=="Average"?50:(Very strong=="Below Average"?25:(Very strong=="Cannot determine"?0:(Very strong=="Poor"?0:0))))))'
var updated = str.replace(/\(([^=]+)/g,'("$1"');
console.log(updated);
基本注册说明:
\( - match a (
([^=]+) - capture one or more characters that is not a =