Optimized tokenization by using pattern matching