regular expression for lua.
NOTE: this module is under heavy development.
- lua-pcre2: https://github.com/mah0x211/lua-pcre2
local regex = require('regex')
i
: Do caseless matching.s
:.
matches anything including NL.m
:^
and$
match newlines within data.u
: Treat pattern and subjects as UTF strings.U
: Do not check the pattern forUTF
valid.x
: Ignore white space and#
comments.o
: compile-once mode that caching a compiled regex.g
: global match.j
: enable JIT compilation.
creates a new regex object.
Params
pattern:string
: string containing expression to be compiled.flgs:string
: regular expression flags.
Returns
re:table
: regex object.err:string
: error message.
matches a compiled regular expression against a given subject string. It returns matched substrings.
Params
sbj:string
: the subject string.offset:number
: offset in the subject at which to start matching.
Returns
arr:table
: array of matched substrings.err:string
: error message.
almost same as match
method but it returns all matched substrings except capture strings.
Params
sbj:string
: the subject string.offset:number
: offset in the subject at which to start matching.
Returns
arr:table
: array of matched substrings.err:string
: error message.
almost same as match
method but it returns offsets of matched substrings.
Params
sbj:string
: the subject string.offset:number
: offset in the subject at which to start matching.
Returns
heads:table
: array of head offset of matched substrings.tails:table
: array of tail offset of matched substrings.err:string
: error message.
almost same as match
method but it returns all offsets of matched substrings except capture strings.
Params
sbj:string
: the subject string.offset:number
: offset in the subject at which to start matching.
Returns
heads:table
: array of head offset of matched substrings.tails:table
: array of tail offset of matched substrings.err:string
: error message.
returns true if there is a matched.
Params
sbj:string
: the subject string.offset:number
: offset in the subject at which to start matching.
Returns
ok:boolean
: true on matched.err:string
: error message.
same as match
instance method.
Params
sbj:string
: the subject string.pattern:string
: string containing expression to be compiled.flgs:string
: 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.
same as matches
instance method.
Params
sbj:string
: the subject string.pattern:string
: string containing expression to be compiled.flgs:string
: 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.
same as indexof
instance method.
Params
sbj:string
: the subject string.pattern:string
: string containing expression to be compiled.flgs:string
: regular expression flags.offset:number
: offset in the subject at which to start matching.
Returns
heads:table
: array of head offset of matched substrings.tails:table
: array of tail offset of matched substrings.err:string
: error message.
same as indexesof
instance method.
Params
sbj:string
: the subject string.pattern:string
: string containing expression to be compiled.flgs:string
: regular expression flags.offset:number
: offset in the subject at which to start matching.
Returns
heads:table
: array of head offset of matched substrings.tails:table
: array of tail offset of matched substrings.err:string
: error message.
same as test
instance method.
Params
sbj:string
: the subject string.pattern:string
: string containing expression to be compiled.flgs:string
: regular expression flags.offset:number
: offset in the subject at which to start matching.
Returns
ok:boolean
: true on matched.err:string
: error message.