Memory Package (Seat)
上面是我的示例数据,下面是我的正则表达式,用于突出括号内的文本,即(),但此表达式不突出显示。
dealerFeatures = dealerFeatures.replace(/(<mark>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/, "$1<mark>$2</mark>$4");
任何人都可以帮我解决这个问题。
答案 0 :(得分:0)
怎么样:
let str='Memory Package (Seat)';
let result=str.replace(/([\s\S]*?\()([\s\S]*?)(\)[\s\S]*)/,'$1'+'<mark>'+'$2'+'</mark>'+'$3');
console.log(result);//Memory Package (<mark>Seat</mark>)
答案 1 :(得分:0)
对于您的示例,您可以捕获第1组> output
Random Forest
375 samples
592 predictors
2 classes: 'alzheimer', 'control'
No pre-processing
Resampling: Cross-Validated (3 fold)
Summary of sample sizes: 250, 250, 250
Resampling results across tuning parameters:
mtry Accuracy Kappa
2 0.6826667 0.3565541
34 0.7600000 0.5194246
591 0.7173333 0.4343563
Accuracy was used to select the optimal model using the largest value.
The final value used for the model was mtry = 34.
中的空缺(
,捕获第2组$1
中的括号之间的字符,并捕获组中的$2
3 )
在替换中你可以使用$3
<强>解释强>
$1<mark>$2</mark>$3
(
(\()
。 )
([^)]+)
)
(\))
&#13;
您的代码可能如下所示:
var str = "Memory Package (Seat)";
var regex = /(\()([^)]+)(\))/g;
console.log(str.replace(regex, "$1<mark>$2</mark>$3"));