Write a pattern
A pattern is a regular expression that is tested case-insensitively, anywhere in the text. Everything else on this page follows from those two facts.
How a pattern is read
We try three readings, in this order, and use the first that works:
- Between slashes. If the pattern starts and ends with
/and is longer than two characters, what is between the slashes is the regex:/^ads?\./means^ads?\.. - As a regex. Anything that is a valid regular expression is used as one.
- As a wildcard. If it is not a valid regex, every character is taken literally, except
*, which matches anything. That is why*.example.comworks: a regex cannot start with*.
Two properties never change: the match is not anchored (it can be found anywhere in the host or rule), and it ignores upper and lower case.
Start the pattern with ^ and end it with $ to pin it to the whole host. Most mistakes on the Watchlist come from not doing that.
Patterns that work
These were checked against the matcher that sends your alerts. The “matches” column lists hosts we tested.
| I want | Pattern | Matches | Does not match |
|---|---|---|---|
| One exact host | ^www\.example\.com$ | www.example.com | a.www.example.com |
| A domain and every subdomain | (^|\.)example\.com$ | example.com, www.example.com | notexample.com |
| Subdomains only, not the bare domain | \.example\.com$ | a.example.com | example.com |
| A host that starts with a word | ^metrics\. | metrics.foo.com | a.metrics.foo.com |
| A family of hosts | ^metrics\..+\.com$ | metrics.foo.com | metrics.com, a.metrics.foo.com |
| Several vendors at once | (^|\.)(vendor-a|vendor-b)\.com$ | vendor-a.com, x.vendor-b.com | vendor-c.com |
| Written between slashes | /^ads?\./ | ad.foo.com, ads.foo.com | bads.foo.com |
| Wildcard form of subdomains | *.example.com | a.example.com, a.b.example.com | example.com, notexample.com |
For “a domain and its subdomains” prefer (^|\.)example\.com$. It is the pattern the Watch button makes on a domain row.
Patterns and path rules
Filter lists hold two kinds of rules. A domain rule blocks a host (||analytics.example.com^). A path rule names a path as well (||example.com/g/collect^, or just /g/collect?).
Your pattern is tested against both:
- for a domain rule, against the host it names;
- for a path rule, against the text of the rule, and also against the host the rule is anchored to, when it has one.
| Pattern | Rule | Result |
|---|---|---|
/g/collect | ||example.com/g/collect^ | matches |
/g/collect | ||analytics.example.com^$third-party | does not match |
example.com | ||analytics.example.com^$third-party | matches |
^analytics\.example\.com$ | ||example.com/g/collect^ | does not match |
\/sst\/_\/set_cookie | /sst/_/set_cookie?val= | matches |
So a bare host such as example.com alerts on both domain rules and path rules under that host, while /g/collect alerts on that path wherever it is listed.
Mistakes that catch too much, or too little
- The dot is any character.
example.comwould also matchexampleXcom. Escape it as\.when it matters. - Slashes at both ends are stripped. A pattern like
/shop/is read asshop, so it also matchesmyshop.com. A path that starts with a slash but does not end with one, such as/g/collect, is used as typed. - A broken regex is not rejected. A typo such as an unclosed
(falls back to the wildcard reading, where it is a literal character. If a watch never fires, check the pattern for this. - Case does not matter.
Example.COMandexample.comare the same watch.
What we refuse
Your pattern runs against every changed rule of every list, every day. To keep that fast and safe, we reject a pattern that:
- is empty;
- is longer than 200 characters;
- uses a backreference such as
\1; - repeats a group that itself contains a repeat, such as
(a+)+, which can take exponential time.
Trying a pattern first
The search on the home page and the Check now button on a watch show which rules exist today. Use them to explore, but note that the search reads its input a little differently: a * is always a wildcard there, and regexes use PostgreSQL syntax. The rules on this page are the ones a watch follows.
Next: change and remove watches.
