[ale] Python regex

Christopher Fowler cfowler at outpostsentinel.com
Sat Sep 9 15:27:04 EDT 2006


I'm in the process of converting a Perl module to a Python equivalent so
it can be used in Python programs.  I'm not exactly a pro with Python.
I may need a bit of help.

One thing I love about Perl is regular expression support.
I'm not sure how I can do the same in Python.  The issue here is that 
I connect to a master database to get a connection string for an 
organizational database.  I now need to connect to that database.
Below is the string that comes from the connect_string column: 

jdbc:mysql://127.0.0.1/AC_DEMO

In Perl I might do the following to extract what I need:

connection_string =~ m/mysql:\/\/(.+?)/\(.+?)$/;
$host = $1
$db = $2

Can someone tell me how I can do the equivalent in Python?

Thanks,
Chris





More information about the Ale mailing list