最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Special Characters in Regex Brackets - Stack Overflow

programmeradmin1浏览0评论

Let's say I want to match one of the following characters: a, b, c, or + (in JavaScript). Do I need to escape the +? Is it /[abc+]/ or /[abc\+]/? Both work in my limited selection of test browsers. Which is (more) correct?

Let's say I want to match one of the following characters: a, b, c, or + (in JavaScript). Do I need to escape the +? Is it /[abc+]/ or /[abc\+]/? Both work in my limited selection of test browsers. Which is (more) correct?

Share Improve this question asked Jul 9, 2010 at 7:40 Casey ChuCasey Chu 25.5k10 gold badges42 silver badges59 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

Regex reference

Under character classes:

Any character except ^-]\ add that character to the possible matches for the character class.

In other words, you don't have to escape the +.

No need to escape the + in character class [xxx]:

/[abc+]/
发布评论

评论列表(0)

  1. 暂无评论