I'm writing a regular expression in Objective-C.
The escape sequence \w
is illegal and emits a warning, so the regular expression /\w/
must be written as @"\\w"
; the escape sequence \?
is valid, apparently, and doesn't emit a warning, so the regular expression /\?/
must be written as @"\\?"
(i.e., the backslash must be escaped).
Question marks aren't invisible like \t
or \n
, so why is \?
a valid escape sequence?
Edit: To clarify, I'm not asking about the quantifier, I'm asking about a string escape sequence. That is, this doesn't emit a warning:
NSString *valid = @"\?";
By contrast, this does emit a warning ("Unknown escape sequence '\w'"):
NSString *invalid = @"\w";