Skip to content

Implement Lua pattern matching for string functions #142

Open

Description

@kyoh86

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:
local result = str:gsub("%s+", "")  -- Remove whitespace
local match = str:match("(%d+)")      -- Extract numbers
local iter = 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?

Activity

  1. upsampled commented on Mar 10, 2026

    @upsampled

    Just to add some details to the ticket if i find time for a PR:

    • the functions are mentioned in comments in
      // {"match", ...},
    • I don't see any implementation that has been commented out so i am assuming this is more a TODO
    • We really need a test case to implement this (should be pretty easy to leverage golang regex to implement once we have tests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions