What's Pattern Matching ?
With Pattern Matching, you specify a pattern which tells Tasker what text you wish to match. For instance, if you want to match any telephone number starting with 0135, you can specify the simple match 0135*. * is a special character which matches any number of any character.
Simple matching is designed to be easy for non-technical people to use.
Where's It Used ?
Simple Matching is used in the following places:
- in the If condition of an action, when the ~ (match) or !~ (not match) operators are specified.
- in text parameters of State and Event contexts
- some other places :-)
- if a pattern is left blank, it will match against anything
- if it is not blank it must match the whole target text
- / means 'or', it divides up multiple possible matches
- a * will match any number of any character. It's not possible to specifically match a * character.
- a + will match one or more of any character. It's not possible to specifically match a + character.
Beware: the condition '%var matches +' will be true if %var has not been assigned a value, because Tasker does not replace variables which do not have a value.
- matching is case-insensitive (magic will match with MagiC) unless the pattern contains an upper-case letter e.g. Magic* will not match against magically, but it will match against Magic Roundabout
- a ! at the very start of a match means not e.g. !*Magic*/*Yellow* matches anything not containing the words Magic or Yellow
- it is not possible to specifically match a ! character at the start of a target (but you could use *!
- help matches help but not helper.
- help* matches helper
- *the* matches the (anywhere)
- 123+ matches 123 and minimally one more character
- + matches anything with at least one character (non-empty)
- the.*way matches the other way and the first way, amongst others
- Help/*shell matches Help or anything ending with shell, case-sensitively
Caller matching (some events and states e.g. Incoming Call) is handled slightly differently.
- C:ANY matches the telephone number of any contact
- C:FAV matches the telephone number of any favourite (starred) contact
- Otherwise: otherwise a match is attempted using the general matching rules against both the caller phone number and the associated contact's name (if there is one).
- !C:ANY matches a number not belonging to a contact
- 077*/Geoff* matches a number starting with 077 or belonging to a contact whose names starts with Geoff
- C:FAV/0123456789 matches any favourite contact or the telephone number 0123456789
Regular Expression Matching
Regular expressions are similar to simple matching patterns but have many more features and are much harder for non-technical people.
Where's It Used ?
Regex Matching is available:
- in the If condition of an action, when the ~R or !~R operators are specified.
- in the Variable Search Replace action
- in the condition of a Variable Value state
Standard Java regular expression matching is applied. The Android Developer site has a reference page.