title: use lookahead to match a string that starts and ends with a quotes and strip the quotes?
body: <p>I'd like to match on strings that start and end with the same quote, but only with the quotes at the start and end:</p>
  
  <pre><code>"foo bar"
  'foo bar'
  "the quick brown fox"
  </code></pre>
  
  <p>But I don't want these matched or stripped:</p>
  
  <pre><code>foo "bar"
  foo 'bar'
  'foo bar"
  "the lazy" dogs
  </code></pre>
  
  <p>I tried with this java regexp but it doesn't quite work for all the cases:</p>
  
  <pre><code>Pattern.compile("^\"|^'(.+)\"$|'$").matcher(quotedString).replaceAll("");
  </code></pre>
  
  <p>I think there is a way to do lookahead, but I don't know how to use it in this case.</p>
  
  <p>Or would it be more efficient to set up an if statement that checks them separately?</p>
  
  <pre><code>Pattern startPattern = Pattern.compile("^\"|^');
  Pattern endPattern = Pattern.compile(\"$|'$");
  
  if (startPattern.matcher(s).find() &amp;&amp; endPattern.matcher(s).find()) {
      ...
  }
  </code></pre>
  
  <p>(of course, this would match <code>'foo bar"</code>, which I do not want)</p>