title: One regular expression to match parts in various positions
body: <p>I'm trying to parse a DSN (from a Symfony application) using regular expressions, in order to link with a secondary application, but using the same database.</p>
  
  <p>The DSN I currently have is:</p>
  
  <pre><code>mysql:dbname=my_db_name;host=localhost
  </code></pre>
  
  <p>with a regex of:</p>
  
  <pre><code>/^(\w+):(dbname=(\w+))?;?(host=(\w+))?/
  </code></pre>
  
  <p>(using <code>preg_match()</code>).  This matches OK, but fails in my test environment because the DSN elements are switched around, thus:</p>
  
  <pre><code>mysql:host=localhost;dbname=my_testdb_name
  </code></pre>
  
  <p>I could just switch them round, yes :-) but I'm sure that extraction of the host and dbname parts from both DSNs is possible with a single regular expression, and I'd like to be able to enhance my knowledge at the same time ;-)  Is there a way I can do this?</p>