Tip of the day: With the UnrealIRCd administration panel you can add and remove server bans and do other server management from your browser.

Introduction to regex (PCRE)

From UnrealIRCd documentation wiki
Jump to navigation Jump to search

Regex is a powerful tool, but it will take time and effort to learn. Once you have learned it, though, it will be useful in many situations. It is very powerful for spamfilters but regex is also used in other software so you won't be learning it just for UnrealIRCd. UnrealIRCd uses the PCRE2 regex engine, this is the same regex engine as used in PHP and is compatible with Perl regex. This is the most popular regex flavor.

UnrealIRCd defaults

Two important things with regards to regex in UnrealIRCd:

  • You don't use slashes at the beginning or start of the regex. So don't use /word/. You simply use word.
  • Regexes are case insensitive by default, so 'm' will match both 'm' and 'M'. If you want it to be case-sensitive then put (?-i) at the start of your regex, such as: (?-i)[a-z]+

Tutorial

An excellent introduction to regex, that explains regex step-by-step, is at http://regular-expressions.info/

There is also https://regex101.com/ which allows you test regex easily via their webinterface. UnrealIRCd uses the PCRE2 syntax, which that site uses by default.

Full docs

The complete PCRE2 regex reference specification is in https://www.pcre.org/current/doc/html/pcre2pattern.html but is rather technical.