I am trying to grep a vector of strings and some of them contain question marks.
I am doing:
grep('\?',vectorofStrings)
and getting this error:
Error: '\?' is an unrecognized escape in character string starting "\?"
How can I determine the proper escaping procedure for '?'
I didn't have luck with backslash escaping, under windows grep. But I managed to make it work by the following:
That is, I enclosed the question mark in character class brackets (
[
and]
), which made the special meaning inactive. The{3}
part is not relevant to the question, I used it to find 3 consecutive question marks.You have to escape
\
as well:Use the
\\
orfixed = TRUE
argument as in:I'd guess
\
is used in R as a normal string escape character, so to pass a literal\
togrep
you might need\\?