add a methed to remove ilegal pattern and optemised finde pattern methed