Pattern matching » History » Version 5
« Previous -
Version 5/13
(diff) -
Next » -
Current version
digitalcircuit, 09/13/2018 04:28 AM
Align tables source view
Pattern matching¶
WORK IN PROGRESS
- Table of contents
- Pattern matching
Upgrade notice¶
This changed in Quassel 0.13
. Follow the migration guide if you're upgrading from an earlier version.
When using the client and core with different versions, some ignore rules will be processed differently.
Breakdown of usage¶
Quassel supports several types of pattern matching for ignore and highlight rules.
Ignore Rules¶
Regular expression |
Item | Pattern matching type |
---|---|---|
Unchecked | Ignore Rule |
Wildcard |
Scope |
Multiple wildcard | |
Checked | Ignore Rule |
Regular expression |
Scope |
Multiple wildcard |
For backwards compatibility, the Regular expression
checkbox only affects Ignore Rule
and not Scope
.
Highlight Rules¶
RegEx |
Item | Pattern matching type |
---|---|---|
Unchecked | Rule |
Phrase |
Sender |
Multiple wildcard | |
Channel |
Multiple wildcard | |
Checked | Rule |
Regular expression |
Sender |
Regular expression | |
Channel |
Regular expression |
This applies to both Local Highlights
and Remote Highlights
(or if using Monolithic, Legacy Highlights
and Highlights
).
Types¶
Phrase¶
This matches exactly what you type.
word
- Matches
word
A word.
has a word in it
- Does not match
wording
Changed in Quassel 0.13
:
Spaces are matched, too, allowing you to be more specific.
spaced
There's a leading space in the example above.
- Matches
, spaced
is spaced out
- Does not match
;spaced
Wildcard¶
Changed in Quassel 0.13
:
This uses simple wildcard substitution with *
and ?
to match any characters or a single character, respectively. The backslash character \
allows matching a literal *
, ?
, or \
.
*Asking questions\? Nope?
- Matches
Asking questions? Nopea
Basking questions? Nope.
- Does not match
Asking questions. Nope.
Asking questions? Nopes.
Implicit wildcard is supported, too, allowing you to match everything except for what you specify.
!*filter*
- Matches
- Everything, unless it contains something from the below list
- Does not match
filter
filtering
#nofilter yo
Exclamation points can be escaped at the beginning to match something that starts with !
(this is not required elsewhere).
\!*filter*
- Matches
!filter
!yes filtering
- Does not match
filter
The \
character can be escaped, too, in case you're matching something that starts with \!
.
\\!*filter*
- Matches
\!filter
\!yes filtering
- Does not match
filter
!filter
Multiple wildcard¶
This allows matching multiple wildcard patterns all in one rule by separating each wildcard with semicolons ;
.
alpha; beta*
- Matches
alpha
betas
beta!
- Does not match
alphamore
nonbeta
Changed in Quassel 0.13
:
More complex wildcard patterns are possible. Use \
to escape special characters.
Alice!*; Bob!*@example.com; Carol*!*; !Caroline!* Dan!*; escaped \; separator; \!not-inverted; \\!slash-prefixed
For ignore rule Scope
, you can use ;
and line breaks interchangeably.
- Matches
Alice![...]
Bob![...]@example.com
Carol[...]![...]
except as noted belowDan![...]
escaped ; separator
!not-inverted
\!slash-prefixed
- Does not match
Caroline![...]
- @Malice![...]
John!
Implicit wildcard is supported, too, allowing you to match everything except for what you specify.
!Announce*!*; !Wheatley!aperture@*
- Matches
- Everything, unless it contains something from the below list
- Does not match
Announce[...]![...]
Wheatley!aperture
[...]@
Regular expression¶
This matches using the full regular expression language, best for complex rules and those already familiar with how regular expressions work. Quassel offers a non-standard !
prefix to invert the rule; if not desired, escape as \!
.
The web provides many resources for testing and verifying regular expressions, including https://regex101.com/ .
Some differences exist from Perl due to design choices and limitations of the Qt framework. These are documented on the Qt documentation site for QRegularExpression with Qt 5, and QRegExp for Qt 4. If you're not sure, you're likely using a Qt 5 build.
simple.\*escape-match.*
- Matches
simpleA*escape-match
simpleA*escape-matchBBBB
- Does not match
not above
simpleA*escape-mat
simple*escape-match
simpleABBBBescape-matchBBBB
Inverted rules are supported, allowing you to match everything except for what you specify.
!invert.\*escape-match.*
- Matches
- Everything, unless it contains something from the below list
- Does not match
invertA*escape-match
invertA*escape-matchBBBB
Changed in Quassel 0.13
:
Exclamation points can be escaped at the beginning to match something that starts with !
(this is not required elsewhere).
\!simple.\*escape-match.*
- Matches
!simpleA*escape-matchBBBB
- Does not match
simpleA*escape-matchBBBB
The \
character can be escaped, too, in case you're matching something that starts with \!
.
\\!simple.\*escape-match.*
- Matches
\!simpleA*escape-matchBBBB
- Does not match
!simpleA*escape-matchBBBB
Migrating to Quassel 0.13
¶
Quassel 0.13
introduced new behavior for pattern matching to provide more flexibility and to improve performance. Unfortunately, due to the complexity of automatically migrating (patches welcome!), you might have to manually migrate some ignore and highlight rules.
Ignore Rules¶
The wildcard matching mode now allows inverting the match with !
, and escaping *
and ?
with \
, so you can match a phrase containing question marks or asterisks. However, this means \
must now be escaped as \\
, and !
at the start must be escaped as \!
.
Before | After | Remarks |
---|---|---|
!literal-matching! |
\!literal-matching! |
Only need to escape ! if it's at the start |
slashes \ within |
slashes \\ within |
|
\! prefixed |
\\! prefixed |
The regular expression format now allows for escaping the first !
in case you want to literally match it, e.g. \!regex.*
.
If your client and core version do not match, they will process ignore rules differently.
If upgrading the Quassel core to 0.13
is not yet feasible, you can workaround this for ignore rules that start with !
or contain \
by migrating them as above. For Permanent
ignore rules, the core will continue to pattern match according to pre-0.13
rules, which isn't likely to cause issues. If it does, you can temporarily change the affected ignore rules to Dynamic
.
Highlight Rules¶
The RegEx
checkbox now affects the Channel
column, too, switching between multiple wildcard and regular expressions as described above.
Your existing highlight rules are automatically migrated to RegEx
if you've specified anything in the Channel
column. If you want to make use of the new multiple wildcard matching mode, uncheck RegEx
and set Channel
to a multiple wildcard pattern.
Example of undoing automatic RegEx
conversion
RegEx |
Item | Pattern |
---|---|---|
Checked | Rule |
(^\|\W)highlight phrase(\W\|$) |
Channel |
#quassel(|-*) | |
Unchecked | Rule |
highlight phrase |
Channel |
#quassel; #quassel-* |
With the Remote Highlights
feature in Quassel 0.13
, the Sender
column behaves the same way as the Channel
column, switching modes according to the RegEx
checkbox.
Technical details¶
For all the technical details and source code changes, take a look at Quassel pull request #415 . MultiPhrase
is not covered here as Quassel only uses it internally for nickname matching.