Documentation

Pattern Matching

Patterns can contain several special character for wild-card matching:

  • * match any number (even none) of characters or white space
  • ? match a single character
  • %d match any number of digits (0-9)
  • %n match a number that starts with a + or - sign
  • %w match any number of alpha characters (a-z) (a word)
  • %a match any number of alphanumeric characters (a-z,0-9)
  • %s match any amount of white space (spaces, tabs)
  • %x match any amount of non-white space
  • %y match any amount of non-white space (same as %x but matches start and end of line)
  • %p match any punctuation
  • %q match any punctuation (same as %p but matches start and end of line)
  • %t match a direction command
  • %e match ESC character for ansi patterns
  • [range] match any amount of characters listed in range
  • ^ force pattern to match starting at the beginning of the line
  • $ force pattern to match ending at the end of the line
  • (pattern) save the matched pattern in a parameter %1 though %99
  • ~ quote the next character to prevent it to be interpreted as a wild card or special character (such as [], (), etc)
  • ~~ match a quote character verbatim
  • {val1|val2|val3|...} match any of the specified strings 
  • @variable match any of the specified strings or keys (works with string lists and record variables)
  • {^string} do not match the specified string
  • &nn matches exactly nn characters (fixed width pattern)
  • &VarName assigns the matched string to the given variable (see below for more info)
  • %/regex/% matches the given Regular Expression (Added in v2.0)
  • %%function() runs any TeSSH function (Added in v2.06)

To save any part of the pattern to the %1..%99 parameters, enclose the part of the parameter in parenthesis.

In specifying a range, you can list specific characters such as [abc] or you can use a range [a-c].

To use a wild card character in the pattern string itself, precede the special character with the ~ quote character. For example, the pattern ~[test~] will match the string [test] rather than being interpreted as a range wild-card pattern. Note that the quote character can be changed in the Special Characters Preferences.

To match a blank line, use the $ pattern by itself. To match multiple lines include $ in the middle of the pattern to match the line boundary.

You can also include variables in your pattern, and the name of the variable will be replaced with its value before the pattern match is performed.

Using &VarName

The &VarName syntax deserves a bit more explanation. It is used to store a matched pattern into a variable directly. For example, if you have a trigger:

#TRIGGER {Status: &Error}

and the server displays

Status: offline

Then the value "offline" is automatically put into the @Error variable with no further action on your part. By default, the &VarName uses the * wildcard. To specify a different wildcard, insert the wildcard just after the & character. In the above example, when the server says

Status: 123

the @Error variable would then contain the string "123". To restrict the trigger to just match a word, change the trigger to:

#TRIGGER {Status: &%wError}

Now the "Status: 123" will not match the trigger. You can use any of the wildcard specifiers, and can also use the square brackets [] to define your own wildcard range.

Sometimes there is alphabetic text in the pattern after the string you want to capture. To delimit this from the variable name, place the variable name in {} brackets. For example, to capture

Ping time: 1000ms

you would use a trigger:

#TRIGGER {Ping time: &%d{Ping}ms}

which will only match digits and will properly set the @Ping variable to 1000.

The &VarName syntax also works with database records and record variables. If you have a record variable @Status and want to set the Ping property, you would use a trigger of:

#TRIGGER {Ping time: &%dStatus.Ping}

NOTE: The patterns matched by the &VarName syntax still count towards the %1..%99 variables and can still be accessed in that manner. So, in the example:

#TRIGGER {Ping time: &Ping Average: &avgPing} {#SHOW %1 %2}

it will automatically set the @Ping and @avgPing variables, and the %1 and %2 parameters will also still be set just as if you had put parenthesis around the &VarName. This is important when you mix &VarName and () in the same trigger. Always count the &VarName as if it also has a parenthesis around it.

Add comment

Login or register to post comments