title: Using regex to extract username from email address
body: <p>My string of text looks like this:</p>
  
  <pre><code>johndoe@domain.com (John Doe)
  </code></pre>
  
  <p>I need to get just the part before the @ and nothing else. The text is coming from a simple XML object if that matters any.</p>
  
  <p>The code I have looks like this:</p>
  
  <pre><code>$authorpre = $key-&gt;{"author"};
  $re1 = '((?:[a-z][a-z]+))';
  
  if ($c = preg_match_all ("/".$re1."/is", $authorpre, $matches))
  {
      $author = $matches[1][0];
  }
  </code></pre>
  
  <p>Sometimes the username might have numbers or an underscore before the @ symbol, which is where the regex stops it seems.</p>