Skip to main content

Lua Pattern Matching for Chat Triggers

Lua Patterns are a unique form of Regular Expressions which allow for very powerful pattern matching.  Lua patterns are slightly different than typical Regular Expressions, so be careful when entering them.  For more information on Lua patterns see: https://www.lua.org/pil/20.2.html

Lua patterns use special character classes and magic characters to enable more powerful pattern searching. 

Character Classes

The following table shows the special character classes.

. all characters
%a letters
%c control characters
%d digits
%l lower case letters
%p punctuation characters
%s space characters
%u upper case letters
%w alphanumeric characters
%x hexadecimal digits
%z the character with representation 0
Magic Characters

Some characters, called magic characters, have special meanings when used in a pattern. The magic characters are

    ( ) . % + - * ? [ ^ $

The following table shows the commonly used magic character modifiers.

+ 1 or more repetitions
* 0 or more repetitions
- also 0 or more repetitions
? optional (0 or 1 occurrence)