package
0.0.0-20221118014540-79c50470ff02
Repository: https://github.com/syhlion/glua-libs.git
Documentation: pkg.go.dev
# README
regexp
origin code: https://github.com/vadv/gopher-lua-libs/tree/master/regexp
Usage
local regexp = require("regexp")
local inspect = require("inspect")
-- regexp.match(regexp, data)
local result, err = regexp.match("hello", "hello world")
if err then error(err) end
if not(result==true) then error("regexp.match()") end
-- regexp.find_all_string_submatch(regexp, data)
local result, err = regexp.find_all_string_submatch("string: '(.*)\\s+(.*)'$", "my string: 'hello world'")
if err then error(err) end
if not(result[1][2] == "hello") then error("not found: "..tostring(result[1][2])) end
if not(result[1][3] == "world") then error("not found: "..tostring(result[1][3])) end
-- regexp:match()
local reg, err = regexp.compile("hello")
if err then error(err) end
local result = reg:match("string: 'hello world'")
if not(result==true) then error("regexp:match()") end
-- regexp:find_all_string_submatch()
local reg, err = regexp.compile("string: '(.*)\\s+(.*)'$")
if err then error(err) end
local result = reg:find_all_string_submatch("string: 'hello world'")
local result = inspect(result, {newline="", indent=""})
if not(result == [[{ { "string: 'hello world'", "hello", "world" } }]]) then error("regexp:find_all_string_submatch()") end
-- regexp.find_all_string_submatch(regexp, data)
local result, err = regexp.find_all_string_submatch("string: '(.*)\\s+(.*)'$", "my string: 'hello world'")
if err then error(err) end
if not(result[1][2] == "hello") then error("not found: "..tostring(result[1][2])) end
if not(result[1][3] == "world") then error("not found: "..tostring(result[1][3])) end
# Functions
regexp.compile(string) returns (regexp_ud, error).
regexp_ud:find_all_string_submatch(string) returns table of table of strings.
No description provided by the author
regexp_ud:match(string) returns bool.
No description provided by the author
regexp.find_all_string_submatch(regular expression string, string) returns (table of table strings, error).
regexp.match(regular expression string, string) returns (bool, error).