You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement Lua pattern matching for string functions #142
Currently, Lua pattern matching is not implemented in the string library. This limits the functionality of several string functions to plain text operations only.
Missing Pattern Matching Support
The following functions are either missing or have incomplete pattern matching:
string.find - Only supports plain text search, pattern matching raises TODO implement pattern matching
string.match - Not implemented (commented out)
string.gsub - Not implemented (commented out)
string.gmatch - Not implemented (commented out)
Current Implementation
In findHelper, pattern matching is explicitly unimplemented:
} else {
l.assert(false) // TODO implement pattern matching
}
Use Cases
Pattern matching is essential for:
Text processing and validation
String transformations (gsub)
Data extraction from structured text
Cleaning up command output
Example of currently failing code:
-- These would fail with current implementation:localresult=str:gsub("%s+", "") -- Remove whitespacelocalmatch=str:match("(%d+)") -- Extract numberslocaliter=str:gmatch("%w+") -- Word iterator
Impact
This limitation forces users to work around missing functionality with manual string manipulation, reducing the utility of go-lua for text processing applications.
Would it be possible to implement Lua's standard pattern matching engine for these string functions?
I'd be up for working on this. I saw #76 from a while back too, but it hasn't been touched since 2023 so not sure if it's still alive. Happy to build on it if you'd rather go that way than start over.
What I had in mind is porting the matcher from Lua 5.2's lstrlib.c pretty directly so it behaves the same as stock Lua (classes, sets, quantifiers, anchors, captures, %b, %f). Then hook it into string.find where the TODO assert is now, and add match, gmatch and gsub. For tests I'd pull cases from Lua's pm.lua and compare against the real interpreter. I'd keep it all in one PR for the string lib.
Activity
upsampled commentedon Mar 10, 2026
Just to add some details to the ticket if i find time for a PR:
go-lua/string.go
Line 188 in 1e37f32
anakafeel commentedon Oct 31, 2026
I'd be up for working on this. I saw #76 from a while back too, but it hasn't been touched since 2023 so not sure if it's still alive. Happy to build on it if you'd rather go that way than start over.
What I had in mind is porting the matcher from Lua 5.2's
lstrlib.cpretty directly so it behaves the same as stock Lua (classes, sets, quantifiers, anchors, captures,%b,%f). Then hook it intostring.findwhere the TODO assert is now, and addmatch,gmatchandgsub. For tests I'd pull cases from Lua'spm.luaand compare against the real interpreter. I'd keep it all in one PR for the string lib.