如何仅在字符串开头和结尾都有引号时,从字符串中删除这些引号?例如:
我使用了
"hello world" => hello world
"hello world => "hello world
hello world" => hello world"
我使用了
gsub
,但是下面的代码会移除每个字符串开头或结尾的引号,无论另一个引号是否存在。'"hello world"'.gsub(/\A"|"\Z/, '')
# => this is ok it returns 'hello world'
'hello world"'.gsub(/\A"|"\Z/, '')
# => returns 'hello world' but should return 'hello world"'