BatClient uses regular expressions (or regexp:s) as the base for matching text from mud. BatClient surrounds the regexp with either ':s or ":s Example: /trig trigname 'trigregexp' triggeraction%;action2 /trig savetrig '^SAVED.$' say I'm saved!%;cheer
Regular expressions are expressive constructs, capable of matching a large variety of strings. They can also be quite complicated, so here are some base pointers to get started. In the examples I surround the regexps with '':s to keep things consistent with BatClient script editing.
Basically the regexp is just text, with some special characters. regexp starting with character ^ matches only lines starting with the text, and $ will match the end of line.
Example: '^You are stunned.$' will only match "You are stunned.". '^You are stunned' Will also match "You are stunned and funny." 'You are stunned' Both the above and eg. "Nubu [bat]: You are stunned."
The special characters: ^$|[](){}\.*+? In order to match any special characters, they must be backlashed with "\", eg. \$ or \\. Additionally, when creating triggers from BeanShell interface, java:s "":s require one round of backlashing and actual triggers need another, for example: \\$ or \\\\ (both backlashes must be backlashed).
Explanations of special characters: . will match any single character * zero or more previous items, eg: .* (0-n anycharacters) + one or more previous items ? zero or one previous items {n} exactly n previous items. eg [0-9]{2} for 2 digits {n,m} n to m previous items [...] Matches any single character inside the brackets, eg. [abc] will match a, b or c. Accepts ranges, eg [a-cf] will match a, b, c or f. Can be combined with *, +, ?, eg. [a-z]* will match any number of lowercase letters. [^..] Similar to above, but matches any character not in the range, eg [^A-Za-z] will match any non-alphabet character. (..) Simple situation is, matches the insides as they are, but stores the part of line matched to be used later (in vars variables in BatClient). Can use | to offer choise of different matches. Eg 'a(bc|cb)d' will match both abcd and acbd | see the (..) above \ escape character.
An example, /trig: /trig testtrig "^You say '(test|[a-z]*[0-9])'$" emote trigger tested!
This will match either "You say 'test'", or any say that begins with any number of small letters and ends with a single digit. Not too useful, but shows some ideas. Check the provided triggers for more examples.
An example, BeanShell triggermanager: triggerManager.newTrigger("litecrit", "(^(Grinning|Smiling|Cackling) (diabolically|devilishly|demonically))", "", false, false, true, new Color[]{Color.RED}, Font.PLAIN);
This will create a trigger to lite criticals red. Notice that there are 3 levels of ():s, and they are matched left to right by opening parenthesises. So, first match (which is lited) is the whole matched line, second match is either Grinning, Smiling or Cackling, and the third match is either diabolically, devilishly or demonically.