shExpMatch()

Shell-glob match of str against pattern; * matches any sequence, ? one character. The whole string must match.

shExpMatch(str, pattern)  →  boolean

Used in about 78% of the real PAC files in the PAC file statistics.

Chromium, Firefox and pacparser convert the glob into a regular expression. * also matches dots, so shExpMatch(host, "*example.com") matches notexample.com; use "*.example.com". Matching on url instead of host lets a query string such as ?r=example.com trigger the rule.

Example

if (shExpMatch(host, "*.example.com") || host == "example.com") {
  return "DIRECT";
}

Windows treats brackets, parentheses and | in a shExpMatch pattern as plain characters

Because Chrome, Edge, Firefox and pactester turn the pattern into a regular expression, some regular-expression syntax happens to work there: shExpMatch(host, "(www|mail).corp.example") matches www.corp.example. Windows (WinHTTP) knows only * and ?. It takes [ ] + ( ) | { } $ literally, so the same pattern never matches there, and a ^ in the pattern changes the result in its own way. Write the alternatives as separate conditions joined with ||. Paste your file into the PAC file tester and pick the Windows (WinHTTP) profile to see the Windows answer.

Check how your own file behaves with the PAC file tester: switch the engine profile between Chromium, Firefox, pacparser and Windows and compare the trace. All engine differences are collected in pactester vs Chrome and Firefox.

Engine notes

EngineBehaviourSource
chromiumConverts the glob to a RegExp escaping only '.', so ( ) | keep their regex meaning.code, verified 2026-10-04
services/proxy_resolver/pac_js_library.h@cb6eb0e7
firefoxSame conversion as Chromium (escapes '.', maps * and ?).code, verified 2026-10-04
netwerk/base/ascii_pac_utils.js@3f73c528
winhttpOnly * and ? are wildcards; [ ] + ( ) | { } $ match themselves, so shExpMatch("ab", "a|b") and shExpMatch("abc", "[ab]bc") are false. A ^ in the pattern changes the match: shExpMatch("x^", "x^") is false. Case-sensitive; * also matches a line break.lab, verified 2026-10-11
Windows 11 25H2

Availability

Derived from each engine's vendored helper library plus its native bindings (see engines).
Functionchromium
<=51
chromium
>=52
firefox
all
pacparser
<=1.4.6
pacparser
>=1.5.1
winhttp
11-25H2
wininet
11-25H2
reference
all
shExpMatchyesyesyesyesyesyesyesyes

Related rules

Frequently asked questions

Can I use (a|b) or [ab] in a shExpMatch pattern?

Not safely. Chrome, Edge, Firefox and pactester happen to accept them because they turn the pattern into a regular expression, but Windows (WinHTTP) treats them as plain characters, so the pattern never matches there. Use separate shExpMatch calls joined with ||, and try the file in the tester at findproxyforurl.net/check/ with the Windows (WinHTTP) profile.

Last updated: