4 ms·
You could use a lexer generator instead of regular expressions, since this is exactly what lexer generators do.
by jules 13y ago
You could use a lexer generator instead of regular expressions, since this is exactly what lexer generators do.
- nikic 13y agoYou can use a lexer, yes - but any fast lexer implementation in a high-level language will actually use the very same technique described here. Generating a character-comparison + goto based FSM works great in C, but has bad performance in PHP (and other dynamic languages). There's a common misconception that regular expressions are slow, but in many cases they offer much better performance than a manual implementation with lots of strpos etc. In the end PCRE does the same thing, but in C and using a JIT compiler. Apart from very simple cases you don't have a chance to keep up with that using PHP code.