Python Regular Expression Pattern Matching Algorithm Brute