assign a matched group values into the variable in php
<p>Using php how to split the usernames,passwords,datadasename,hostname,etc into a variable.</p>

<p>For Example:</p>

<blockquote>
  <p>$db =
  "databasename://username:password@hostname/dbname"</p>
  
  <p>$
  databasename = databasename</p>
  
  <p>$user = username </p>
  
  <p>$pass = password </p>
  
  <p>$host = hostname </p>
  
  <p>$dbname = dbname</p>
</blockquote>

<p>I have tried with grouping in regular expression. but I don't know how to assign the group values into the variable.</p>

<blockquote>
  <p>preg_match("(^([a-z]<em>?)://([a-z]</em>?):([a-z]<em>?)@[a-z]</em>?)/([a-z]*?)$)", $db , $matches);</p>
</blockquote>
