Namespace: regex

The regex namespace contains functions that implement the C++11 (and higher) Regular Expression functionalities. These are added to enhance what regex can be done from within Lua as Lua’s built-in regex features are limited.

You can access this namespace via:

ashita.regex.

Below are the functions available in this namespace.


ashita.regex.match

Applies the given pattern to a message to find all matches. (std::regex_match)
For more info, visit: https://en.cppreference.com/w/cpp/regex/regex_match

function ashita.regex.match(msg, pattern);

Parameters

  • msg - (string) The message to search for the pattern within.
  • pattern - (string) The pattern to apply while matching.

Returns

  • table|nil - A table of matches on success, nil otherwise.

ashita.regex.search

Applies the given pattern to a message to find all matches. (std::regex_search)
For more info, visit: https://en.cppreference.com/w/cpp/regex/regex_search

function ashita.regex.search(msg, pattern);

Parameters

  • msg - (string) The message to search for the pattern within.
  • pattern - (string) The pattern to apply while matching.

Returns

  • table|nil - A table of matches on success, nil otherwise.

ashita.regex.replace

Replaces all matches within a string. (std::regex_replace)
For more info, visit: https://en.cppreference.com/w/cpp/regex/regex_replace

function ashita.regex.replace(msg, pattern, replace);

Parameters

  • msg - (string) The message to search for the pattern within.
  • pattern - (string) The pattern to apply while matching.
  • replace - (string) The replacement string to use.

Returns

  • string|nil - The new replaced string on success, nil otherwise.

ashita.regex.split

Splits a string via the given pattern. (std::sregex_token_iterator)
For more info, visit: https://en.cppreference.com/w/cpp/regex/regex_token_iterator

function ashita.regex.split(msg, pattern);

Parameters

  • msg - (string) The message to search for the pattern within.
  • pattern - (string) The pattern to apply while matching.

Returns

  • table|nil - A table of the split parts on success, nil otherwise.