logoalt Hacker News

thaliaarchitoday at 4:58 AM1 replyview on HN

I find it interesting that MicroPython's `re` module[0] is implemented with a backtracking regular expression engine from re1.5[1], instead of one of the linear-time engines from the same library. (Russ Cox covers the various engines in the excellent blog series[2] which re1 is a companion to.) I figure the choice was made due to binary size or memory constraints, though they're all quite small.

[0]: https://github.com/micropython/micropython/tree/master/lib/r...

[1]: https://github.com/pfalcon/re1.5/tree/v0.8.2

[2]: https://swtch.com/~rsc/regexp/regexp2.html


Replies

matt_trentinitoday at 6:01 AM

Yes, it was chosen for low size and memory constraints. But it is limited in features (like counted repetitions):

https://docs.micropython.org/en/latest/library/re.html

so alternatives to provide additional features have been discussed... Either extending the existing module or swapping to a more feature-rich library. Possibly even doing so for larger micros that can afford the additional flash/memory, though that makes support more challenging.

show 1 reply