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?
views:
48answers:
2
+7
A:
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 +
.
Aistina
2010-07-09 07:50:41
Or `?`,`*` and `.` which a lot of people (including myself) often seem to do out of habit as well.
gnarf
2010-07-09 08:52:22