title: Using Bash regex match (=~) where regex includes quotes (" characters)
body: <p>I want to use Bash regex matching (with the =~ operator) to match a string which includes quotes. Say for example I have the following string and I want to extract the text between quotes:</p>
  
  <pre><code>foo='"Hello World!"'
  </code></pre>
  
  <p>My first try was to put the regex in strong quotes like so to force the quotes to be regular characters.</p>
  
  <pre><code>[[ "$foo" =~ '".*"' ]]
  </code></pre>
  
  <p>That fails because Bash interprets this as a string match rather than a regex.</p>
  
  <p>Then I tried to escape the quotes with \ like so:</p>
  
  <pre><code>[[ "$foo" =~ \".*\" ]]
  </code></pre>
  
  <p>That fails (EDIT: Actually, it doesn't. It fails if there's no space between \" and ]] but the version here works just fine.) because the first \ is in plain bash text and fails to escape the quote (I think. The coloring in VIM indicates that the second quote is escaped but not the first and running the script fails).</p>
  
  <p>So is there some way I can escape the " characters without transforming the regex match into a string match?</p>