# shExpMatch()

Source: https://findproxyforurl.net/functions/shexpmatch/ · last updated 2026-10-11

`shExpMatch(str, pattern)` → boolean

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

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

```js
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](https://findproxyforurl.net/check/) and pick the Windows (WinHTTP) profile to see the Windows answer.


## Engine notes

- chromium: Converts the glob to a RegExp escaping only '.', so ( ) | keep their regex meaning. (source: code, verified 2026-10-04)
- firefox: Same conversion as Chromium (escapes '.', maps * and ?). (source: 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. (source: lab, verified 2026-10-11)

## 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.

