Python Find Patterns Sql