Match Patterns


Content scripts operate on a set of URLs defined by match patterns. You can put one or more match patterns in the matches part of a content script’s section of the manifest, as well as in the exclude_matches section. This page describes the match pattern syntax — the rules you need to follow when you specify which URLs your content script affects.

What match patterns are

A match pattern is essentially a URL that begins with a permitted scheme (httphttpsfileftp, or chrome-extension), and that can contain * characters. The special pattern <all_urls> matches any URL that starts with a permitted scheme. Each match pattern has 3 parts:

  1. scheme — for example, http or file or *
  2. host — for example, or * or *; if the scheme is file, there is no host part
  3. path — for example, /*/foo*, or /foo/bar

Note: Access to file URLs isn’t automatic. The user must visit the extensions management page and opt in to file access for each extension that requests it.

Match pattern syntax

Here’s the basic syntax:

<url-pattern> := <scheme>://<host><path>
<scheme> := `*` | `http` | `https` | `file` | `ftp` | `chrome-extension`
<host> := `*` | `*.` <any char except `/` and `*`>+
<path> := `/` <any chars>

The meaning of * depends on whether it’s in the schemehost, or path part. If the scheme is *, then it matches either http or https. If the host is just *, then it matches any host. If the host is *.hostname, then it matches the specified host or any of its subdomains. In the path section, each * matches 0 or more characters. The following table shows some valid patterns.

PatternWhat it doesExamples of matching URLs
http://*/*Matches any URL that uses the http scheme
http://*/foo*Matches any URL that uses the http scheme, on any host, as long as the path starts with /foo
https://**barMatches any URL that uses the https scheme, is on a host (such as, or, as long as the path starts with /foo and ends with bar the specified URL
file:///foo*Matches any local file whose path starts with /foofile:///foo/bar.htmlfile:///foo*Matches any URL that uses the http scheme and is on the host
*://*Matches any URL that starts with or
chrome-extension://*/*Matches any URL pointing to an extension (the first * represents a filter for extension IDs, the second for paths)chrome-extension://askla…asdf/options.html
<all_urls>Matches any URL that uses a permitted scheme. (See the beginning of this section for the list of permitted schemes.)

Here are some examples of invalid pattern matches:

Bad patternWhy it’s bad path
http://*foo/bar* in the host can be followed only by a . or /
http://foo.*.bar/bazIf * is in the host, it must be the first character
http:/barMissing scheme separator (/ should be //)
foo://*Invalid scheme

Some schemes are not supported in all contexts.