forked from vadv/gopher-lua-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
46 lines (42 loc) · 1.09 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package regexp
import (
"log"
inspect "github.com/alexjx/gopher-lua-libs/inspect"
lua "github.com/yuin/gopher-lua"
)
// regexp_ud:match(string)
func ExampleMatch() {
state := lua.NewState()
Preload(state)
source := `
local regexp = require("regexp")
local reg, err = regexp.compile("hello")
if err then error(err) end
local result = reg:match("string: 'hello world'")
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// true
}
// regexp_ud:find_all_string_submatch(string)
func ExampleFindAllStringSubmatch() {
state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
local regexp = require("regexp")
local inspect = require("inspect")
local reg, err = regexp.compile("string: '(.*)\\s+(.*)'$")
if err then error(err) end
local result = reg:find_all_string_submatch("string: 'hello world'")
print(inspect(result, {newline="", indent=""}))
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// { { "string: 'hello world'", "hello", "world" } }
}