Home›Java›Mods›Luamine-re2addon
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

Code (Text):
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

Plugin details

Read from the plugin's own plugin.yml.

Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

Luamine-re2addon is a free Minecraft Java mod. Compatible with Minecraft 1.21. Downloaded 7 times (via Spigot). Download it and open it directly in the game.

Explore more