add a function to get pattern length