Compatibility
Minecraft: Java Edition
Platforms
Links
Tags
Creators
Details
Re2Addon
Adds RE2 regular expression support to LuaMine scripts, via the re2j library.
Requires LuaMine to be installed and enabled.
Why RE2 instead of standard regex?
RE2 is specifically designed to guarantee linear-time matching with no catastrophic backtracking — the class of bug where a crafted or just unlucky regex pattern can hang a thread for seconds or minutes on certain inputs. That matters here: LuaMine scripts are, by nature, less trusted than your own server code, so exposing regex to them safely means picking an engine that can't be turned into a denial-of-service vector by an ordinary (even non-malicious) pattern.
Usage
local re2 = require("re2")
-- Free functions - pattern as a string
re2.matches("[0-9]+", "hello123") -- false (whole string must match)
re2.find("[0-9]+", "hello123world") -- 5, 8
re2.findAll("[0-9]+", "a1 b22 c333") -- table of {start, end, match}
re2.replace("[0-9]+", "a1b2c3", "X") -- "aXb2c3" (first match only)
re2.replaceAll("[0-9]+", "a1b2c3", "X") -- "aXbXcX"
re2.split(",", "one,two,three") -- {"one", "two", "three"}
re2.quote("a.b*c") -- literal-escaped string
re2.valid("[unclosed") -- false
-- Object-oriented style - compile once, reuse
local p = re2.compile("[a-z]+")
p:matches("hello")
p:find("123hello456")
p:replace("abc123def", "X")
Pattern strings passed to the free functions are cached internally, so calling e.g.
re2.matches("some.pattern", text) repeatedly with the same pattern string doesn't
recompile the regex from scratch every time.
Links
- LuaMine (required dependency)
- Documentation
- Source

