Liblouis User's and Programmer's Manual
2.14 The match Opcode ¶
For historical reasons despite being fairly similar in functionality
both the context
opcode (see context
) and the match opcode exist and are in use
in modern braille tables. But in the future they might be merged under
some common opcode. For that reason consider the match opcode
somewhat experimental.
match pre-pattern characters post-pattern dots
-
This opcode allows for matching a string of characters via pre and post patterns. The patterns are specified using an expression syntax somewhat like regular expressions (see pattern expression syntax). A single hyphen (‘-’) by itself means no pattern is specified.
The following will replace ‘xyz’ with the dots ‘1346-13456-1356’ when it appears in the string ‘abxyzcd’.
match ab xyz cd 1346-13456-1356
The following will replace ‘ONE’ with ‘3456-1’ when it starts the input and is followed by ‘:’
match ^ ONE : 3456-1
The pre-pattern
and the post-pattern
can contain
any of the following expressions:
- ‘[ ]’
Expression can be any of the characters between the brackets. If only one character present then the brackets are not needed unless it is a special character, in which it should be escaped with the backslash.
- ‘.’
Expression can be any character.
- ‘%[ ]’
Expression is a character with the attributes listed between the brackets. If only one character is present then the brackets are not needed. The set of attributes are specified as follows:
- ‘_’
space
- ‘#’
digit
- ‘a’
letter
- ‘u’
uppercase
- ‘l’
lowercase
- ‘.’
punctuation
- ‘$’
sign
- ‘~’
seqdelimiter
- ‘<’
seqbeforechars
- ‘>’
seqafterchars
- ‘^’
Match at the end of input processing (or beginning depending of the direction pre or post).
- ‘$’
Same as ‘^’.
For example the following will replace ‘bb’ with the dots ‘23’ when it is between letters.
match %a bb %a 23
The following will replace ‘con’ with the dots ‘25’ when it is preceded by a space or beginning of input, and followed by an ‘s’ and then any letter.
match %[^_] con s%a 25
Similar to regular expressions the pattern expressions can contain grouping, quantifiers and even negation:
- ‘( )’
Expressions between parentheses are grouped together as one expression.
- ‘!’
The following expression is negated.
- ‘?’
The previous expression must match zero or one times.
- ‘*’
The previous expression must match zero or more times.
- ‘+’
The previous expression must match one or more times.
- ‘|’
Either the previous or the following expressions must match.
For example the following will replace ‘ing’ with the dots ‘346’ when it is not preceded by a space or beginning of input. What follows after the ‘ing’ does not matter, hence the ‘-’.
match !%[^_] ing - 346
The following will replace ‘con’ with the dots ‘25’ when it is preceded by a space, or beginning of input; then followed by a ‘c’ that is followed by any character but ‘h’.
match %[^_] con c!h 25