title: Case insensitive regex in Bash
body: <p>I want to know which method is better to check if a var (input by user on keyboard) matches with a regex in a case insensitive way. I know there are some different possibilities. Example: I want a regex matching an empty value and all of this list: <code>Y</code>, <code>N</code>, <code>y</code>, <code>n</code>, <code>Yes</code>, <code>No</code>, <code>YES</code>, <code>NO</code></p>
  
  <p>I searched looking different methods. Not sure if could be another better. I'll put a couple of them working for me.</p>
  
  <ul>
  <li><p>First one is a little "tricky" setting all to uppercase for the comparison:</p>
  
  <pre><code>#!/bin/bash
  yesno="null" #any different value for initialization is valid
  while [[ ! ${yesno^^} =~ ^[YN]$|^YES$|^NO$|^$ ]]; do
      read -r yesno
  done
  </code></pre></li>
  <li><p>Second one is using <code>shopt -s nocasematch</code>. But not sure if after doing that it can be reverted because I don't want to set this for all the script.</p>
  
  <pre><code>#!/bin/bash
  yesno="null" #any different value for initialization is valid
  shopt -s nocasematch
  while [[ ! ${yesno} =~ ^[yn]$|^yes$|^no$|^$ ]]; do
      read -r yesno
  done
  </code></pre></li>
  </ul>
  
  <p>Can these regex get improved in any way?
  Is there a better (more elegant) method?
  On second method, is there a way to revert that setting?</p>