Javascript precisely replaces the specified Chinese characters in the string

problem description

I want to replace a string of specified characters with what I want. I have tried many ways to have problems. I am looking for a great solution ~

.

/ / str is a formula of string type, which only replaces the Operand a with d, but cannot replace an in the Operand abc with d
let str = "axiabc+ (Macroc)";

Jun.12,2021

\ b match word boundaries

let str = 'a+abc+a+(m*c)';
let reg = /\ba\b/g;
console.log(str.replace(reg,'d'));
Menu