---
id: api/utilities/minimatch
title: Cypress.minimatch()
description: Cypress automatically includes minimatch and exposes it as Cypress.minimatch.
section: api
source_path: docs/api/utilities/minimatch.mdx
version: e6c8d867c21227247f14714fb5690c7c018983c5
updated_at: '2026-08-08T12:39:37.868Z'
---
# Cypress.minimatch

Cypress automatically includes [minimatch](https://github.com/isaacs/minimatch) and exposes it as `Cypress.minimatch`.

Use `Cypress.minimatch` to test out glob patterns against strings.

## Syntax

```
Cypress.minimatch(target: string, pattern: string, options?: MinimatchOptions);
```

### Usage

**Correct Usage**

```
Cypress.minimatch('/users/1/comments/2', '/users/*/comments', {  matchBase: true,})
```

**Incorrect Usage**

```
cy.minimatch() // Errors, cannot be chained off 'cy'
```

## Examples

By default Cypress uses `minimatch` to test glob patterns against request URLs.

If you're struggling with writing the correct pattern you can iterate much faster by testing directly in your Developer Tools console.

```
// test that the glob you're writing matches the request's url// returns trueCypress.minimatch('/users/1/comments', '/users/*/comments', {  matchBase: true,})// returns falseCypress.minimatch('/users/1/comments/2', '/users/*/comments', {  matchBase: true,})
```

We're adding the `{ matchBase: true }` option because under the hood Cypress actually uses that option by default.

Now let's test out `**` support.

```
// ** matches against all downstream path segments// returns trueCypress.minimatch('/foo/bar/baz/123/quux?a=b&c=2', '/foo/**', {  matchBase: true,})// whereas * matches only the next path segment// returns falseCypress.minimatch('/foo/bar/baz/123/quux?a=b&c=2', '/foo/*', {  matchBase: false,})
```

## Notes

In minimatch glob syntax, `?` is a wildcard that matches **any single character** — it does not represent a literal `?`. If your pattern needs to match the literal `?` that precedes a URL query string, escape it with a backslash. In a JavaScript string you write `\\?` so that minimatch receives the character sequence `\?`:

```
// INCORRECT – unescaped ? is a wildcard, not a literal question markCypress.minimatch('/users?_limit=3', '/users?_limit=*', { matchBase: true })// false — the ? in the pattern matches any single character, not the// literal ? in the URL// CORRECT – \\? sends \? to minimatch, which matches a literal ?Cypress.minimatch('/users?_limit=3', '/users\\?_limit=*', {  matchBase: true,}) // true
```

## See also

*   [Bundled Libraries](/llm/markdown/app/references/bundled-libraries.md)
*   [cy.intercept() – Glob Pattern Matching URLs](/llm/markdown/api/commands/intercept.md#Glob-Pattern-Matching-URLs)
