RegEx Question in Python
Posted on 2004-08-11
I am beginning to dabble in some Python. I am trying to connect to a database so that I can build a table and then populate that table. Once I get this working then it will become a cron script. The purpose for this is to build citeria for searches against a database.
At any rate, here is my script so far:
row = cursor.fetchone()
row = str(row)
p = re.compile('[,()\']')
row = p.sub('',row)
p = re.compile('(PDB_[0-9])')
Now this is inside of a loop that is returning the names of databases from a query. The database name takes the form of PDB_nnnnn(c), that's five numbers and an optional character. As you can see, I am trying to match on this pattern ( re.compile('(PDB_[0-9])') ) and this does work, except there are intermediate database files with stuff like _old, _tmp and such on the end of the PDB_nnnnn.
My question is how can I modify the re.compile('(PDB_[0-9])') to filter out those database names that have the _xxx on the end of them?
By the way, I am going against MySQL and to get all the databases I am issuing the query "SHOW DATABASES".
Thanks for your help