improve the performance of regexp version (still slow though)
improve performance.