The matchPattern function added. 

//TODO improve it.