Hello and welcome to the forums!
Your example uses a
pattern_replace, which is a token filter. It operates on individual tokens in the text, rather than on the string as a whole. By the time the string
i have 2 cars and 2cars gets to the filter, it's been transformed into a stream of tokens:
['i', 'have', '2', 'cars', 'and', '2cars']. The regex gets applied to each of those tokens, and
cars don't match on their own, but the
2cars token does.
If you wanted
2 cars to be its own token, that's something that would be controlled by a "tokenizer" rather than a "token filter." For more details, see anatomy of an analyzer.