寻求可打包适配LuaJIT的便携正则表达式库(开箱即用无需安装)
LuaJIT Portable PCRE-Compatible Regex Libraries (No Extra Installs, Windows-First)
Hey there! Since you're building a portable LuaJIT app and need PCRE/PCRE2-style regex support (without Lpeg), here are the best self-contained options that can be bundled with your source, interpreter, and app into a single, ready-to-run package:
1. lj2pcre (LuaJIT + PCRE2 FFI Binding)
- Why it fits: This is a lightweight FFI-based binding for PCRE2, built specifically for LuaJIT. It supports full PCRE2 syntax, and crucially, you can compile it to statically link the PCRE2 library directly into your LuaJIT executable.
- Portability on Windows:
- Compile using MinGW or MSVC to create a single
.exethat includes LuaJIT, your script, and the PCRE2 regex logic. No separate DLLs required—users just run the exe and go. - If you don’t want to compile from source, you can find pre-built static binaries for Windows that work out of the box.
- Compile using MinGW or MSVC to create a single
- Usage example:
local pcre = require("lj2pcre") local match = pcre.match("Hello World", "Hello (\\w+)") print(match[1]) -- Outputs "World"
2. Statically Linked rex_pcre
- Why it fits:
rex_pcreis a widely used Lua binding for PCRE, and when statically linked against PCRE and LuaJIT, it eliminates external dependencies. - Windows bundling:
- Grab a pre-compiled static
rex_pcre.dll(or compile your own) and bundle it alongside your LuaJIT interpreter and script. - Use tools like Enigma Virtual Box or 7-Zip SFX to package all files into a single self-extracting executable. When run, the tool extracts the files to a temporary directory, runs your app, and cleans up afterward—completely transparent to the user.
- Grab a pre-compiled static
- Key note: Make sure you use the static build of
rex_pcre(not the dynamic one that relies on system PCRE libraries) to avoid missing DLL errors.
3. LuaJIT-Regexp (Pure LuaJIT Bytecode, PCRE-Like)
- Why it fits: If you want something that doesn’t require compiling C code, this library implements a PCRE-compatible regex engine entirely in LuaJIT-optimized bytecode. It’s slower than native PCRE bindings but works without any external C dependencies.
- Portability: Just drop the
.luafile into your project,requireit, and bundle it with your other files. No DLLs or compilation needed—perfect for quick, portable setups.
Pro Tips for Windows Portability
- Always test your bundled app on a fresh Windows machine (no Lua or PCRE installed) to ensure there are no hidden dependencies.
- For single-file deployment, tools like
srluaorluajit-srluacan compile your Lua script and the required libraries into a standalone LuaJIT executable—great for keeping things clean.
内容的提问来源于stack exchange,提问作者dzikakulka
相关产品推荐
相关产品推荐

