Switch to using regex for pattern matching