Javascript 使用正则表达式替换字符串中的字符
我有一个字符串,里面有这样的词 比如说Javascript 使用正则表达式替换字符串中的字符,javascript,regex,Javascript,Regex,我有一个字符串,里面有这样的词 比如说 var str="hello <00dansld> this is ur system <00aldjs> and you are <00jdak>" 因此,我必须将括号内的单词用粗体表示,并将其打印在html页面中,这样在html页面中看起来就像 hello < <b>00dansld<b> > this is ur system < <b> 00aldjs
var str="hello <00dansld> this is ur system <00aldjs> and you are <00jdak>"
因此,我必须将括号内的单词用粗体表示,并将其打印在html页面中,这样在html页面中看起来就像
hello < <b>00dansld<b> > this is ur system < <b> 00aldjs <b> > .
我怎么做?我曾想过使用正则表达式,但我不知道如何使用它?您可以使用正则表达式,并用$1替换每次发生的事件:
const text=您好,这是您的系统;
const replaced=text.replace//g,“$1”;
document.body.innerHTML=已替换;字符串是否已固定?请阅读。我已经尽我所能翻译了你的代码,如果你自己翻译的话会更好。如果我想保留括号和粗体字符,可能会有重复的内容。@Saurabhkapor我编辑了我的答案以匹配你的评论。谢谢你的解决方案