Skip to content

Commit 90ca96d

Browse files
committed
Update README.md
1 parent c887ed7 commit 90ca96d

File tree

1 file changed

+57
-79
lines changed

1 file changed

+57
-79
lines changed

README.md

Lines changed: 57 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# lua-regex
22

3-
regular expression for lua.
3+
[![test](https://github.com/mah0x211/lua-regex/actions/workflows/test.yml/badge.svg)](https://github.com/mah0x211/lua-regex/actions/workflows/test.yml)
4+
[![codecov](https://codecov.io/gh/mah0x211/lua-regex/branch/master/graph/badge.svg)](https://codecov.io/gh/mah0x211/lua-regex)
5+
46

5-
**NOTE:** this module is under heavy development.
7+
regular expression for lua.
68

79

810
## Dependencies
@@ -51,7 +53,7 @@ creates a new regex object.
5153
## Instance Methods
5254

5355

54-
### arr, err = re:match( sbj [, offset] )
56+
## arr, err = regex:match( sbj [, offset] )
5557

5658
matches a compiled regular expression against a given subject string. It returns matched substrings.
5759

@@ -66,7 +68,7 @@ matches a compiled regular expression against a given subject string. It returns
6668
- `err:string`: error message.
6769

6870

69-
### arr, err = re:matches( sbj [, offset] )
71+
## arr, err = regex:matches( sbj [, offset] )
7072

7173
almost same as `match` method but it returns all matched substrings except capture strings.
7274

@@ -81,7 +83,7 @@ almost same as `match` method but it returns all matched substrings except captu
8183
- `err:string`: error message.
8284

8385

84-
### heads, tails, err = re:indexof( sbj [, offset] )
86+
## arr, err = regex:indexof( sbj [, offset] )
8587

8688
almost same as `match` method but it returns offsets of matched substrings.
8789

@@ -92,14 +94,13 @@ almost same as `match` method but it returns offsets of matched substrings.
9294

9395
**Returns**
9496

95-
- `heads:table`: array of head offset of matched substrings.
96-
- `tails:table`: array of tail offset of matched substrings.
97+
- `arr:table`: array of offsets of matched substrings. 1st index is the start offset of matched substring, and 2nd index is the end offset of matched substring, and 3rd index is the start offset of 1st capture string, and 4th index is the end offset of 1st capture string, and so on.
9798
- `err:string`: error message.
9899

99100

100-
### heads, tails, err = re:indexesof( sbj [, offset] )
101+
## arr, err = regex:indexesof( sbj [, offset] )
101102

102-
almost same as `match` method but it returns all offsets of matched substrings except capture strings.
103+
almost same as `match` method but it returns all offsets of matched substrings **except capture strings**.
103104

104105
**Params**
105106

@@ -108,12 +109,11 @@ almost same as `match` method but it returns all offsets of matched substrings e
108109

109110
**Returns**
110111

111-
- `heads:table`: array of head offset of matched substrings.
112-
- `tails:table`: array of tail offset of matched substrings.
112+
- `arr:table`: array of offsets of matched substrings. 1st index is the start offset of matched substring, and 2nd index is the end offset of matched substring, and so on.
113113
- `err:string`: error message.
114114

115115

116-
### ok, err = re:test( sbj [, offset] )
116+
## ok, err = regex:test( sbj [, offset] )
117117

118118
returns true if there is a matched.
119119

@@ -132,89 +132,67 @@ returns true if there is a matched.
132132
## Static Methods
133133

134134

135-
### arr, err = regex.match( sbj, pattern [, flgs [, offset]] )
136-
137-
same as `match` instance method.
138-
139-
**Params**
140-
141-
- `sbj:string`: the subject string.
142-
- `pattern:string`: string containing expression to be compiled.
143-
- `flgs:string`: [regular expression flags](#regular-expression-flags).
144-
- `offset:number`: offset in the subject at which to start matching.
145-
146-
**Returns**
147-
148-
- `arr:table`: array of matched substrings.
149-
- `err:string`: error message.
150-
151-
152-
### arr, err = regex.matches( sbj, pattern [, flgs [, offset]] )
153-
154-
same as `matches` instance method.
155-
156-
**Params**
157-
158-
- `sbj:string`: the subject string.
159-
- `pattern:string`: string containing expression to be compiled.
160-
- `flgs:string`: [regular expression flags](#regular-expression-flags).
161-
- `offset:number`: offset in the subject at which to start matching.
162-
163-
**Returns**
164-
165-
- `arr:table`: array of matched substrings.
166-
- `err:string`: error message.
167-
168-
169-
### heads, tails, err = regex.indexof( sbj, pattern [, flgs [, offset]] )
135+
## arr, err = regex.match( sbj, pattern [, flgs [, offset]] )
170136

171-
same as `indexof` instance method.
137+
same as the following code:
172138

173-
**Params**
139+
```lua
140+
local re, err = regex.new( pattern, flgs )
141+
if re then
142+
return re:match( sbj, offset )
143+
end
144+
return nil, err
145+
```
174146

175-
- `sbj:string`: the subject string.
176-
- `pattern:string`: string containing expression to be compiled.
177-
- `flgs:string`: [regular expression flags](#regular-expression-flags).
178-
- `offset:number`: offset in the subject at which to start matching.
179147

180-
**Returns**
148+
## arr, err = regex.matches( sbj, pattern [, flgs [, offset]] )
181149

182-
- `heads:table`: array of head offset of matched substrings.
183-
- `tails:table`: array of tail offset of matched substrings.
184-
- `err:string`: error message.
150+
same as the following code:
185151

152+
```lua
153+
local re, err = regex.new( pattern, flgs )
154+
if re then
155+
return re:matches( sbj, offset )
156+
end
157+
return nil, err
158+
```
186159

187-
### heads, tails, err = regex.indexesof( sbj, pattern [, flgs [, offset]] )
188-
189-
same as `indexesof` instance method.
190160

191-
**Params**
161+
## arr, err = regex.indexof( sbj, pattern [, flgs [, offset]] )
192162

193-
- `sbj:string`: the subject string.
194-
- `pattern:string`: string containing expression to be compiled.
195-
- `flgs:string`: [regular expression flags](#regular-expression-flags).
196-
- `offset:number`: offset in the subject at which to start matching.
163+
same as the following code:
197164

198-
**Returns**
165+
```lua
166+
local re, err = regex.new( pattern, flgs )
167+
if re then
168+
return re:indexof( sbj, offset )
169+
end
170+
return nil, err
171+
```
199172

200-
- `heads:table`: array of head offset of matched substrings.
201-
- `tails:table`: array of tail offset of matched substrings.
202-
- `err:string`: error message.
203173

174+
## arr, err = regex.indexesof( sbj, pattern [, flgs [, offset]] )
204175

205-
### ok, err = regex.test( sbj, pattern [, flgs [, offset]] )
176+
same as the following code:
206177

207-
same as `test` instance method.
178+
```lua
179+
local re, err = regex.new( pattern, flgs )
180+
if re then
181+
return re:indexesof( sbj, offset )
182+
end
183+
return nil, err
184+
```
208185

209-
**Params**
210186

211-
- `sbj:string`: the subject string.
212-
- `pattern:string`: string containing expression to be compiled.
213-
- `flgs:string`: [regular expression flags](#regular-expression-flags).
214-
- `offset:number`: offset in the subject at which to start matching.
187+
## ok, err = regex.test( sbj, pattern [, flgs [, offset]] )
215188

216-
**Returns**
189+
same as the following code:
217190

218-
- `ok:boolean`: true on matched.
219-
- `err:string`: error message.
191+
```lua
192+
local re, err = regex.new( pattern, flgs )
193+
if re then
194+
return re:test( sbj, offset )
195+
end
196+
return nil, err
197+
```
220198

0 commit comments

Comments
 (0)