Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mah0x211 committed May 20, 2024
1 parent c887ed7 commit 90ca96d
Showing 1 changed file with 57 additions and 79 deletions.
136 changes: 57 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# lua-regex

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


**NOTE:** this module is under heavy development.
regular expression for lua.


## Dependencies
Expand Down Expand Up @@ -51,7 +53,7 @@ creates a new regex object.
## Instance Methods


### arr, err = re:match( sbj [, offset] )
## arr, err = regex:match( sbj [, offset] )

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

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


### arr, err = re:matches( sbj [, offset] )
## arr, err = regex:matches( sbj [, offset] )

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

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


### heads, tails, err = re:indexof( sbj [, offset] )
## arr, err = regex:indexof( sbj [, offset] )

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

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

**Returns**

- `heads:table`: array of head offset of matched substrings.
- `tails:table`: array of tail offset of matched substrings.
- `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.
- `err:string`: error message.


### heads, tails, err = re:indexesof( sbj [, offset] )
## arr, err = regex:indexesof( sbj [, offset] )

almost same as `match` method but it returns all offsets of matched substrings except capture strings.
almost same as `match` method but it returns all offsets of matched substrings **except capture strings**.

**Params**

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

**Returns**

- `heads:table`: array of head offset of matched substrings.
- `tails:table`: array of tail offset of matched substrings.
- `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.
- `err:string`: error message.


### ok, err = re:test( sbj [, offset] )
## ok, err = regex:test( sbj [, offset] )

returns true if there is a matched.

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


### arr, err = regex.match( sbj, pattern [, flgs [, offset]] )

same as `match` instance method.

**Params**

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

**Returns**

- `arr:table`: array of matched substrings.
- `err:string`: error message.


### arr, err = regex.matches( sbj, pattern [, flgs [, offset]] )

same as `matches` instance method.

**Params**

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

**Returns**

- `arr:table`: array of matched substrings.
- `err:string`: error message.


### heads, tails, err = regex.indexof( sbj, pattern [, flgs [, offset]] )
## arr, err = regex.match( sbj, pattern [, flgs [, offset]] )

same as `indexof` instance method.
same as the following code:

**Params**
```lua
local re, err = regex.new( pattern, flgs )
if re then
return re:match( sbj, offset )
end
return nil, err
```

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

**Returns**
## arr, err = regex.matches( sbj, pattern [, flgs [, offset]] )

- `heads:table`: array of head offset of matched substrings.
- `tails:table`: array of tail offset of matched substrings.
- `err:string`: error message.
same as the following code:

```lua
local re, err = regex.new( pattern, flgs )
if re then
return re:matches( sbj, offset )
end
return nil, err
```

### heads, tails, err = regex.indexesof( sbj, pattern [, flgs [, offset]] )

same as `indexesof` instance method.

**Params**
## arr, err = regex.indexof( sbj, pattern [, flgs [, offset]] )

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

**Returns**
```lua
local re, err = regex.new( pattern, flgs )
if re then
return re:indexof( sbj, offset )
end
return nil, err
```

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

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

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

same as `test` instance method.
```lua
local re, err = regex.new( pattern, flgs )
if re then
return re:indexesof( sbj, offset )
end
return nil, err
```

**Params**

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

**Returns**
same as the following code:

- `ok:boolean`: true on matched.
- `err:string`: error message.
```lua
local re, err = regex.new( pattern, flgs )
if re then
return re:test( sbj, offset )
end
return nil, err
```

0 comments on commit 90ca96d

Please sign in to comment.