For the latest stable version, please use Emilua API 0.10!

regex

Types

regex

Functions

new(options: table) → regex

Constructor.

options
pattern: string

The pattern to match against.

grammar

The grammar.

Currently it has support for:

  • "basic".

  • "extended".

  • "ecma".

ignore_case: boolean = false

Whether to ignore casing.

nosubs: boolean = false

When performing matches, all marked sub-expressions are treated as non-marking sub-expressions.

optimize: boolean = false

Whether to optimize the regex.

Functions

match(re: regex, str: string|byte_span) → matches…​

Try to match the pattern against the whole string str. If successful, then returns the captures from the pattern; otherwise it returns nil. If re specifies no captures, then the whole match is returned.

search(re: regex, str: string|byte_span) → table

Scan through str looking for the first location where the regular expression pattern produces a match, and return a corresponding match object. The returned table contains the following string keys:

"empty": boolean

Whether match was unsuccessful.

The table also contains numeric keys from 0 to the number of specified capture groups. 0 will represent the whole match and subsequent indexes are present if a corresponding match for that capturing group was found. Each element will be a table with the following members:

"start": integer

The index for the first character that matched.

"end_": integer`

The index for the last character that matched.

split(re: regex, str: string|byte_span) → string[]|byte_span[]

Split str by the occurrences of re.

patsplit(re: regex, str: string|byte_span) → string[]|byte_span[]

Returns occurrences of re in str.