我想要一个
的gsub'here is \"what\" I am "thinking"'.gsub('"','\"') -> 'here is \"what\" I am \"thinking\"'
即如果它已经是\"
,则将它留下。我的gsub会是什么?
THX
答案 0 :(得分:2)
使用负面的lookbehind:
puts 'here is \"what\" I am "thinking"'.gsub(/(?<!\\)"/, '\"')
# => here is \"what\" I am \"thinking\"