Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用正则表达式替换字符串中的字符_Javascript_Regex - Fatal编程技术网

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我编辑了我的答案以匹配你的评论。谢谢你的解决方案