title: Bash regex: replace string with any number of characters
body: <p>I'm trying to remove colouring codes from a string; e.g. from: <code>\033[36;1mDISK\033[0m</code> to: <code>DISK</code></p>
  
  <p>my regex looks like this: <code>\033.*?m</code> so match '\033' followed by any number of chars, terminated by 'm'</p>
  
  <p>when I search for the pattern, it finds a match; <code>[[ "$var" =~ $regex ]]</code> evaluates to <em>true</em></p>
  
  <p>however when I try to replace matches, nothing happens and the same string is returned.</p>
  
  <p>Here's my complete script:</p>
  
  <pre><code>regex="\033.*?m"
  var="\033[36;1mDISK\033[0m"
  
  if [[ "$var" =~ $regex ]]
  then
          echo "matches"
          echo ${var//$regex}
  else
          echo "doesn't match!"
  fi
  </code></pre>
  
  <p>The problem appears to be with the match any number of any character part of the regex. I can successfully replace <code>DISK</code> but if I change that to <code>D.*K</code> or <code>D.*?K</code> it fails.</p>
  
  <p>Note in all above cases the pattern claims to match the string but fails when replacing. Not too sure where to go with this now, any help appreciated.</p>
  
  <p>Thanks</p>