Noel Jones wrote: > Many years ago I worked on a system with a 32k limit on pcre > expressions. Ever since then, everything I've checked has > been 64k, and then I gave up checking. I expect any > non-ancient system will support 64k, and some maybe even more. > (To clarify for others following along, this is a characters > per single expression limit, not a filesize or number of > expressions per file limit)
Thanks for the info. > > Now compare that against: > > > > /^([0-9]{1,3}\.){4}(foo|bar|baz)$/ > > > > which will again fail on the fourth character, but there is only one > > pattern which matches the same strings as the 3 patterns above. > > This example is pretty easy to see that combining is better. Exactly. Fortunately this is the very common example that will very easily lend itself to this optimisation. > It's not so clear if you create 32k of complex gibberish if it > will actually operate faster as there may be significant > startup times. YMMV and all that. I agree completely. > BTW, with pcre you should use the the non-greedy flag inside > parenthesis if you're not doing $n substitutions. This saves > another smidgen of time and memory. > /^(?:[0-9]{1,3}\.){4}(?:foo|bar|baz)$/ Good tip, thanks. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/