shExpMatch()
Shell-glob match of str against pattern; * matches any sequence, ? one character. The whole string must match.
shExpMatch(str, pattern) → booleanChromium, 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
| Engine | Behaviour | Source |
|---|---|---|
| chromium | Converts the glob to a RegExp escaping only '.', so ( ) | keep their regex meaning. | code, verified 2026-10-04 |
| firefox | Same conversion as Chromium (escapes '.', maps * and ?). | code, verified 2026-10-04 |
| winhttp | Only * 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 |
Availability
| Function | chromium | chromium | firefox | pacparser | pacparser | winhttp | wininet | reference |
|---|---|---|---|---|---|---|---|---|
shExpMatch | yes | yes | yes | yes | yes | yes | yes | yes |
Related rules
- Trailing * in a host pattern matches attacker-controlled suffixes PAC-X002
- Leading * without a dot matches look-alike domains PAC-X004
- Pattern with leading and trailing * is a substring match PAC-X009
- Hostname pattern applied to url instead of host PAC-C001
- IP range matched as a text prefix PAC-X006
- Wildcard inside a domain label PAC-X012
- Regular-expression syntax inside a shExpMatch pattern PAC-K015
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.