CC: Tweaked

CC: Tweaked

42M Downloads

Add Regular Expressions

DDAN-17 opened this issue ยท 2 comments

commented

I don't know what API this would be added to, but it's just a simple change.

commented
commented

Thanks for the suggestion!

I'm afraid there's a couple of concerns I have here which I don't think make this worth implementing:

  • There is a question here about what "type" of regular expression we support. We could just expose Java's implementation directly, but that's a bit of a portability and future-proofing nightmare. PCRE would be the obvious choice, but embedding that in Java is a nightmare.

  • A lot of regular expression engines are vulnerable to DDoSes. For instance, running Pattern.compile("(.*a){10000}").matcher("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!").matches(); will hang the JVM for tens of seconds, which is definitely not desirable for ComputerCraft!

  • As @Erb3 says, Lua already has a string pattern library already. I'm wary of adding something which overlaps with existing Lua functionality.

One thing possibly worth noting, is that it's pretty easy to build more advanced string matching functionality yourself in pure Lua! For instance, LuLPeg adds a neat DSL for string parsing.