Hi all,
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.
The DSN I currently have is:
mysql:dbname=my_db_name;host=localhost
with a regex of:
/^(\w+):(dbname=(\w+))?;?(host=(\w+))?/
(using preg_match()
). This matches OK, but fails in my test environment because the DSN elements are switched around, thus:
mysql:host=localhost;dbname=my_testdb_name
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?