use switch statement and simplify the regexp generation statement
Add more comments for pattern compiler