/} /是JS中的有效正则表达式:
alert('}}}'.replace(/}/g,"!"))
但是,the ECMA standard似乎不允许:
PatternCharacter ::SourceCharacter but not any of:
^ $\ . * + ? ( ) [ ] { } |
最佳答案
http://www.regular-expressions.info/characters.html:
原文链接:https://www.f2er.com/js/429646.htmlMost regular expression flavors treat the brace { as a literal
character,unless it is part of a repetition operator like {1,3}. So
you generally do not need to escape it with a backslash,though you
can do so if you want. An exception to this rule is the
java.util.regex package: it requires all literal braces to be escaped.
似乎javascript不是例外.