-1
我想一個GSUB,做GSUB正則表達式,從而逃脫了雙引號呆着
'here is \"what\" I am "thinking"'.gsub('"','\"') -> 'here is \"what\" I am \"thinking\"'
即離開它alsone如果它已經是\"
。我的gsub會是什麼?
THX
我想一個GSUB,做GSUB正則表達式,從而逃脫了雙引號呆着
'here is \"what\" I am "thinking"'.gsub('"','\"') -> 'here is \"what\" I am \"thinking\"'
即離開它alsone如果它已經是\"
。我的gsub會是什麼?
THX
使用負回顧後:
puts 'here is \"what\" I am "thinking"'.gsub(/(?<!\\)"/, '\"')
# => here is \"what\" I am \"thinking\"
你爲什麼投票結束? – timpone 2014-10-22 06:38:10