title: PHP Regex for a string with alphanumeric and special characters
body: <p>I tried and could not find an answer for this issue, so I'm asking this question.</p>
  
  <p>I need to create a regex for password validation and it must have following conditions.</p>
  
  <ul>
  <li>At least one letter</li>
  <li>At least one number</li>
  <li>At least one special letter ~ ! ^ ( ) { } &lt; > % @ # &amp; * + = _ -</li>
  <li>Must not contain $ ` , . / \ ; : ' " |</li>
  <li>Must be between 8-40 characters</li>
  <li>No spaces</li>
  </ul>
  
  <p>I have created following regex but it does not work properly.</p>
  
  <pre><code>preg_match('/[A-Za-z\d$!^(){}?\[\]&lt;&gt;~%@#&amp;*+=_-]{8,40}$/', $newpassword)
  </code></pre>
  
  <p>Can somebody please help me to fix this regex properly?</p>
  
  <p>Thanks.</p>