Match Substring Python Function