Remove leading and trailing quotes from string if both are present
<p>How do I remove leading and trailing quotes from a string <strong>only if both are present?</strong> For example</p>

<pre><code>"hello world" =&gt; hello world
"hello world =&gt; "hello world
hello world" =&gt; hello world"
</code></pre>

<p>I tried it with <code>gsub</code>, but the following removes every leading or trailing quotes, regardless if the other is present</p>

<pre><code>'"hello world"'.gsub(/\A"|"\Z/, '')
# =&gt; this is ok it returns 'hello world'

'hello world"'.gsub(/\A"|"\Z/, '')
# =&gt; returns 'hello world' but should return 'hello world"'
</code></pre>