Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've written a JS regexp parser and engine. It did not fit in 40 lines.

The most obnoxious part is backreferences. The atom \3 is a backreference if the whole regexp contains at least 3 capture groups; otherwise it is an octal (!) escape for char code 3. But you don't know how many capture groups there are until you're done parsing. This is why JS regexp parsers sometimes must make two passes!



FWIW back references mean you're way outside of "regular languages" so e.g. DFA usually don't support them.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: