regexp

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2023 License: BSD-3-Clause Imports: 2 Imported by: 0

README

regexp GoDoc

Lua module for 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

Documentation

Overview

Package regexp implements golang package regexp functionality for lua.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(L *lua.LState) int

regexp.compile(string) returns (regexp_ud, error)

func FindAllStringSubmatch

func FindAllStringSubmatch(L *lua.LState) int

regexp_ud:find_all_string_submatch(string) returns table of table of strings

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Match

func Match(L *lua.LState) int

regexp_ud:match(string) returns bool

func Preload

func Preload(L *lua.LState)

Preload adds regexp to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local regexp = require("regexp")

func SimpleFindAllStringSubmatch

func SimpleFindAllStringSubmatch(L *lua.LState) int

regexp.find_all_string_submatch(regular expression string, string) returns (table of table strings, error)

func SimpleMatch

func SimpleMatch(L *lua.LState) int

regexp.match(regular expression string, string) returns (bool, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL