1 <h1>Match Patterns
</h1>
4 <a href=
"declare_permissions#host-permissions">Host
7 and
<a href=
"content_scripts">content script
</a>
9 matching {{^is_apps}}are{{:}}is{{/is_apps}} based on a set of URLs defined by
10 <dfn>match patterns
</dfn>. A match pattern is essentially a
11 URL that begins with a permitted scheme (
<code>http
</code>,
12 <code>https
</code>,
<code>file
</code>, or
<code>ftp
</code>,
13 and that can contain '
<code>*
</code>' characters.
15 <code><all_urls
></code> matches any URL
16 that starts with a permitted scheme.
17 Each match pattern has
3 parts:
</p>
21 <li> <em>scheme
</em> —
22 for example,
<code>http
</code> or
<code>file
</code>
26 Access to
<code>file
</code> URLs isn't automatic.
27 The user must visit the extensions management page
28 and opt in to
<code>file
</code> access for each extension that requests it.
31 <li> <em>host
</em> —
32 for example,
<code>www.google.com
</code>
33 or
<code>*.google.com
</code>
35 if the scheme is
<code>file
</code>,
36 there is no
<em>host
</em> part
38 <li> <em>path
</em> —
39 for example,
<code>/*
</code>,
<code>/foo*
</code>,
40 or
<code>/foo/bar
</code>. The path must be present in a
41 host permission, but is always treated
46 <p>Here's the basic syntax:
</p>
49 <em><url-pattern
></em> :=
<em><scheme
></em>://
<em><host
></em><em><path
></em>
50 <em><scheme
></em> := '*' | 'http' | 'https' | 'file' | 'ftp'
51 <em><host
></em> := '*' | '*.'
<em><any char except '/' and '*'
></em>+
52 <em><path
></em> := '/'
<em><any chars
></em>
56 The meaning of '
<code>*
</code>' depends on whether
57 it's in the
<em>scheme
</em>,
<em>host
</em>, or
<em>path
</em> part.
58 If the
<em>scheme
</em> is
<code>*
</code>,
59 then it matches either
<code>http
</code> or
<code>https
</code>,
60 and
<strong>not
</strong> <code>file
</code>, or
<code>ftp
</code>.
61 If the
<em>host
</em> is just
<code>*
</code>,
62 then it matches any host.
63 If the
<em>host
</em> is
<code>*.
<em>hostname
</em></code>,
64 then it matches the specified host or any of its subdomains.
65 In the
<em>path
</em> section,
66 each '
<code>*
</code>' matches
0 or more characters.
67 The following table shows some valid patterns.
70 <table class=
"simple">
73 <th style=
"margin-left:0; padding-left:0">Pattern
</th>
74 <th style=
"margin-left:0; padding-left:0">What it does
</th>
75 <th style=
"margin-left:0; padding-left:0">Examples of matching URLs
</th>
80 <code>http://*/*
</code>
83 <td>Matches any URL that uses the
<code>http
</code> scheme
</td>
86 http://www.google.com/
<br>
87 http://example.org/foo/bar.html
93 <code>http://*/foo*
</code>
97 Matches any URL that uses the
<code>http
</code> scheme, on any host,
98 as long as the path starts with
<code>/foo
</code>
102 http://example.com/foo/bar.html
<br>
103 http://www.google.com/foo
<b></b>
109 <code>https://*.google.com/foo*bar
</code>
113 Matches any URL that uses the
<code>https
</code> scheme,
114 is on a google.com host
115 (such as www.google.com, docs.google.com, or google.com),
116 as long as the path starts with
<code>/foo
</code>
117 and ends with
<code>bar
</code>
121 http://www.google.com/foo/baz/bar
<br>
122 http://docs.google.com/foobar
128 <code>http://example.org/foo/bar.html
</code>
131 <td>Matches the specified URL
</td>
134 http://example.org/foo/bar.html
140 <code>file:///foo*
</code>
143 <td>Matches any local file whose path starts with
<code>/foo
</code>
147 file:///foo/bar.html
<br>
154 <code>http://
127.0.0.1/*
</code>
158 Matches any URL that uses the
<code>http
</code> scheme
159 and is on the host
127.0.0.1
162 http://
127.0.0.1/
<br>
163 http://
127.0.0.1/foo/bar.html
169 <code>*://mail.google.com/*
</code>
173 Matches any URL that starts with
174 <code>http://mail.google.com
</code> or
175 <code>https://mail.google.com
</code>.
179 http://mail.google.com/foo/baz/bar
<br>
180 https://mail.google.com/foobar
186 <code><all_urls
></code>
190 Matches any URL that uses a permitted scheme.
191 (See the beginning of this section for the list of permitted
195 http://example.org/foo/bar.html
<br>
203 Here are some examples of
<em>invalid
</em> pattern matches:
206 <table class=
"simple">
209 <th style=
"margin-left:0; padding-left:0">Bad pattern
</th>
210 <th style=
"margin-left:0; padding-left:0">Why it's bad
</th>
214 <td><code>http://www.google.com
</code></td>
215 <td>No
<em>path
</em></td>
219 <td><code>http://*foo/bar
</code></td>
220 <td>'*' in the
<em>host
</em> can be followed only by a '.' or '/'
</td>
224 <td><code>http://foo.*.bar/baz
</code></td>
225 <td>If '*' is in the
<em>host
</em>, it must be the first character
</td>
229 <td><code>http:/bar
</code></td>
230 <td>Missing
<em>scheme
</em> separator (
"/" should be
"//")
</td>
234 <td><code>foo://*
</code></td>
235 <td>Invalid
<em>scheme
</em></td>
241 Some schemes are not supported in all contexts.