regex - Distinguish quotation mark (") from backslash and quotation mark (\") -
this simplified version of issue trying solve. so, try not hack answer :)
in r, default
'"' == '\"' therefore, when use
urlencode('\"') urlencode('"') i got same result: %22
however, want is
%5c%22 , %22 respectively above 2 commands.
the goal encode string such 'parse "i * \"good\"" adj' url string
parse%20%22i%20am%20*%20%5c%22good%5c%22%22%20as%20adj any ideas?
========== update =====
given confusions above question. further clarify that: understand r treats '\"' '"'. want r automatically, rather me manually, convert user's string input of '\"' '\\\"' while treating input string of '"' '"' or '\"', equivalent anyway.
the r string literals treat backslash escaping symbol. if write \", backslash escaping ", since not valid escape sequence, backslash ignored.
to write literal backslash, use \\, double backslashes.
urlencode('\\"') ## => "%5c%22" urlencode('"') ## => "%22" urlencode('parse "i * \\"good\\"" adj') ## => "parse%20%22i%20am%20*%20%5c%22good%5c%22%22%20as%20adj" see ideone demo
Comments
Post a Comment