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

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -