Slightly smarter regex matcher