regular expression for [allchars]

后端 未结 1 1951
孤独总比滥情好
孤独总比滥情好 2020-11-30 15:49

I am trying to match something like [allchar] with a regular expression and be able to pull it out and replace it with other content

Here is what I am trying

相关标签:
1条回答
  • 2020-11-30 16:30
    reg = new RegExp("\\[.*?\\]", "g");
    x = "[abc123.;.] this is more content";
    console.log(x.replace(reg, "[contentreplacedwith]"));
    

    If you use RegExp constructor the there's no need to pass / delimiters and the options like g for global are a second argument.

    0 讨论(0)
提交回复
热议问题