title: Regular Expression not allow duble underscores
body: <p>I am writing my website user registration part, I have a simple regular expression as follows:</p>
  
  <pre><code>if(preg_match("/^[a-z0-9_]{3,15}$/", $username)){
      // OK...
  }else{
      echo "error";
      exit();
  }
  </code></pre>
  
  <p>I don't want to let users to have usernames like: '<code>___</code>' or '<code>x________y</code>', this is my function which I just wrote to replace duble underscores:</p>
  
  <pre><code>function replace_repeated_underScores($string){
      $final_str = '';
      $str_len = strlen($string);
      $prev_char = '';
      for($i = 0; $i &lt; $str_len; $i++){
          if($i &gt; 1){
              $prev_char = $string[$i - 1];
          }
          $this_char = $string[$i];
          if($prev_char == '_' &amp;&amp; $this_char == '_'){
  
          }else{
              $final_str .= $this_char;
          }
      }
      return $final_str;
  }
  </code></pre>
  
  <p>And it works just fine, but I wonder if I could also check this with regular expression and not another function.</p>
  
  <p>I would appreciate any help.</p>