rspamd_regexp
Rspamd regexp is an utility module that handles rspamd perl compatible regular expressions
Functions:
Function | Description |
---|---|
rspamd_regexp.create(pattern[, flags]) |
Creates new rspamd_regexp. |
rspamd_regexp.import_glob(glob_pattern[, flags]) |
Creates new rspamd_regexp from glob. |
rspamd_regexp.import_plain(plain_string[, flags]) |
Creates new rspamd_regexp from plain string (escaping specials). |
rspamd_regexp.get_cached(pattern) |
This function gets cached and pre-compiled regexp created by either create . |
rspamd_regexp.create_cached(pattern[, flags]) |
This function is similar to create but it tries to search for regexp in the. |
Methods:
Method | Description |
---|---|
re:get_pattern() |
Get a pattern for specified regexp object. |
re:set_limit(lim) |
Set maximum size of text length to be matched with this regexp (if lim is. |
re:set_max_hits(lim) |
Set maximum number of hits returned by a regexp. |
re:get_max_hits(lim) |
Get maximum number of hits returned by a regexp. |
re:search(line[, raw[, capture]]) |
Search line in regular expression object. |
re:match(line[, raw_match]) |
Matches line against the regular expression and return true if line matches. |
re:matchn(line, max_matches, [, raw_match]) |
Matches line against the regular expression and return number of matches if line matches. |
re:split(line) |
Split line using the specified regular expression. |
re:destroy() |
Destroy regexp from caches if needed (the pointer is removed by garbage collector). |
The module rspamd_regexp
defines the following functions.
rspamd_regexp.create(pattern[, flags])
Creates new rspamd_regexp
Parameters:
pattern {string}
: pattern to build regexp. If this pattern is enclosed in //
then it is possible to specify flags after itflags {string}
: optional flags to create regular expressionReturns:
{regexp}
: regexp argument that is not automatically destroyedBack to module description.
rspamd_regexp.import_glob(glob_pattern[, flags])
Creates new rspamd_regexp from glob
Parameters:
pattern {string}
: pattern to build regexp.flags {string}
: optional flags to create regular expressionReturns:
{regexp}
: regexp argument that is not automatically destroyedBack to module description.
rspamd_regexp.import_plain(plain_string[, flags])
Creates new rspamd_regexp from plain string (escaping specials)
Parameters:
pattern {string}
: pattern to build regexp.flags {string}
: optional flags to create regular expressionReturns:
{regexp}
: regexp argument that is not automatically destroyedBack to module description.
rspamd_regexp.get_cached(pattern)
This function gets cached and pre-compiled regexp created by either create
or create_cached
methods. If no cached regexp is found then nil
is returned.
Parameters:
pattern {string}
: regexp patternReturns:
{regexp}
: cached regexp structure or nil
Back to module description.
rspamd_regexp.create_cached(pattern[, flags])
This function is similar to create
but it tries to search for regexp in the
cache first.
Parameters:
pattern {string}
: pattern to build regexp. If this pattern is enclosed in //
then it is possible to specify flags after itflags {string}
: optional flags to create regular expressionReturns:
{regexp}
: regexp argument that is not automatically destroyedBack to module description.
The module rspamd_regexp
defines the following methods.
re:get_pattern()
Get a pattern for specified regexp object
Parameters:
No parameters
Returns:
{string}
: pattern lineBack to module description.
re:set_limit(lim)
Set maximum size of text length to be matched with this regexp (if lim
is
less or equal to zero then all texts are checked)
Parameters:
lim {number}
: limit in bytesReturns:
No return
Back to module description.
re:set_max_hits(lim)
Set maximum number of hits returned by a regexp
Parameters:
lim {number}
: limit in hits countReturns:
{number}
: old number of max hitsBack to module description.
re:get_max_hits(lim)
Get maximum number of hits returned by a regexp
Parameters:
No parameters
Returns:
{number}
: number of max hitsBack to module description.
re:search(line[, raw[, capture]])
Search line in regular expression object. If line matches then this
function returns the table of captured strings. Otherwise, nil is returned.
If raw
is specified, then input is treated as raw data not encoded in utf-8
.
If capture
is true, then this function saves all captures to the table of
values, so the first element is the whole matched string and the
subsequent elements are ordered captures defined within pattern.
Parameters:
line {string}
: match the specified line against regexp objectmatch {bool}
: raw regexp instead of utf8 onecapture {bool}
: perform subpatterns capturingReturns:
{table or nil}
: table of strings or tables (if capture
is true) or nil if not matchedBack to module description.
re:match(line[, raw_match])
Matches line against the regular expression and return true if line matches (partially or completely)
Parameters:
line {string}
: match the specified line against regexp objectmatch {bool}
: raw regexp instead of utf8 oneReturns:
{bool}
: true if line
matchesBack to module description.
re:matchn(line, max_matches, [, raw_match])
Matches line against the regular expression and return number of matches if line matches
(partially or completely). This process stop when max_matches
is reached.
If max_matches
is zero, then only a single match is counted which is equal to
re:match
If max_matches
is negative, then all matches are considered.
Parameters:
line {string}
: match the specified line against regexp objectmax_matches {number}
: maximum number of matchesmatch {bool}
: raw regexp instead of utf8 oneReturns:
{number}
: number of matches found in the line
argumentBack to module description.
re:split(line)
Split line using the specified regular expression. Breaks the string on the pattern, and returns an array of the tokens. If the pattern contains capturing parentheses, then the text for each of the substrings will also be returned. If the pattern does not match anywhere in the string, then the whole string is returned as the first token.
Parameters:
line {string/text}
: line to splitReturns:
{table}
: table of split line portions (if text was the input, then text is used for return parts)Back to module description.
re:destroy()
Destroy regexp from caches if needed (the pointer is removed by garbage collector)
Parameters:
No parameters
Returns:
No return
Back to module description.
Back to top.