Rewrite using regexp for better performance.