title: How to use preg_match()/preg_replace() on specific lengths and patterns
body: <p>I'm having so much trouble understanding this, could someone explain it?</p>
  
  <p>I'm extremely concerned about sanitizing data on my website and I'd like to go the extra mile and strip everything that's not supposed to be there. here's an example I end up handling a lot of hex values which only contain hyphens, numbers and letters A through F in a string like this</p>
  
  <pre><code>7d43637d-780c-4703-8467-13525d590
  </code></pre>
  
  <p>How would I go about writing a preg_match/replace that would check for
  8 characters '0-9' 'A-F' 'a-f', hyphen, 4 chars, hyphen, 4 chars, hyphen, 4 chars, hyphen, 9 chars?</p>
  
  <p>Would it go a bit like this?</p>
  
  <pre><code>pre_replace("/([0-9a-fA-F]{8})\/([-])\/([0-9a-fA-F]{4})\/([-])\/([0-9a-fA-F]{4})\/([-])\/([0-9a-fA-F]{4})\/([-])\/([0-9a-fA-F]{9})\", "", $string);
  </code></pre>
  
  <p>I'm sorry it's so long and confusing, I am definitely open to alternative ideas to accomplish this.</p>
  
  <p>I also need one that will check 'A-Z' 'a-z' '0-9' '-' '_' and 32 characters long</p>
  
  <p>I really wish there was an online generator for this, maybe if I can understand how it is done I'll build one for other poor souls.</p>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>Using AbraCadaver's code I was able to get this to work using </p>
  
  <pre><code>if(!preg_match("/[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{9}/i", $string)){
      echo 'error';
  } else {
      //continue code
  }
  </code></pre>