Module rsre

Require: require("rsre")

Index

Function

escape()

Escapes special characters in text with ''. Returns a string which, when interpreted as a regex, matches exactly text.

Class

Captures

Match

Regex

Api reference

class rsre.Match: userdata
start: integer

Get the 1-indexed byte start position of the match (inclusive).

stop: integer

Get the 1-indexed byte stop position of the match (exclusive).

text: string

Get the matched substring.

range(self): integer, integer

Get the start and stop positions of the match.

class rsre.Captures: userdata
get(self, index: integer): rsre.Match

Get the match at the provided index.

name(self, name: string): rsre.Match

Get match with the provided name.

len(self): integer

Get the total number of matches.

class rsre.Regex: userdata
staticmethod new(pattern: string): rsre.Regex

Compile a new regex.

match(self, hay: string): boolean

Test if the regex matches the provided string.

find(self, hay: string, pos?: integer): rsre.Match

Find the first, leftmost match after pos.

captures(self, hay: string, pos?: integer): rsre.Captures

Find the first, leftmost captures after pos.

replace(self, text: string, rep: string, limit?: integer): string

Replace matches in text with rep, optionally up to limit times.

split(self, text: string, limit?: integer): string[]

Split a string at every match, optionally up to limit times.

rsre.escape(text: string): string

Escapes special characters in text with ‘’. Returns a string which, when interpreted as a regex, matches exactly text.

Parameters:

text (string) – The string to escape