Glob to Regex Converter

Glob patterns are the friendly wildcards you type into .gitignore, shell commands, and build configs. Sometimes you need the same matching logic as a real regular expression — for a linter rule, a router, or a language that has regex but no glob. This converter translates a glob into an equivalent regex and lets you test a path against it instantly.

How to use the Glob to Regex Converter

Type a glob into the Glob pattern box. The equivalent regex appears immediately, ready to copy into your code. Type a path into Test a path to see whether the generated regex matches it — useful for confirming the translation behaves the way you expect before you ship it.

Two toggles control the dialect. Globstar makes ** match across directory separators (so src/**/*.ts matches src/a/b/c.ts); with it off, every * stops at a slash. Anchor wraps the output in ^ and $ so it must match the whole string rather than a substring — turn it off if you want to embed the pattern inside a larger regex.

The converter understands *, **, ?, character classes like [a-z] and [!0-9], and brace expansion such as {js,ts,jsx}. All regex metacharacters in the literal parts of your glob are escaped automatically.

Globs vs. regular expressions

Globs and regexes solve overlapping problems with very different syntax. A glob is intentionally minimal — designed for matching filenames at a shell prompt — so * means "any run of characters in this path segment," ? means "one character," and that is nearly the whole language. A regex is a full pattern grammar where * means "zero or more of the previous token," . means "any character," and dozens of metacharacters carry meaning.

Because the symbols overlap but mean different things, you cannot use a glob where a regex is expected (or vice versa) without translating. The mapping is mechanical: glob * becomes regex [^/]*, glob ? becomes [^/], and a literal dot in the glob becomes the escaped \. in the regex. Globstar is the one piece with no direct single-token equivalent — ** becomes .*, and **/ becomes an optional-segment group so it can also match zero directories deep.

Brace expansion is a convenience borrowed from the shell: file.{js,ts} is shorthand for two alternatives, which maps cleanly to a regex alternation (?:js|ts). Character classes are the one place the two languages already agree, so they pass through almost unchanged, apart from converting the glob negation marker ! into the regex caret.

Common use cases

  • Porting ignore rules. Translate .gitignore or .dockerignore entries into regexes for a tool that only speaks regex.
  • Routing and matching. Convert a user-friendly glob config into the regex your router or middleware actually compiles.
  • CI file filters. Turn a path glob from a pipeline config into a regex for a step that filters changed files.
  • Learning. Seeing the regex a glob expands to makes both languages click — especially the difference between * and **.

Frequently asked questions

What does globstar do?

With globstar on, ** matches across directory separators, so src/**/*.ts matches files at any depth. With it off, * and ** both stop at a slash and only match within a single path segment.

Does it support brace expansion?

Yes. A pattern like *.{png,jpg,gif} becomes a regex alternation. One level of braces is supported, which covers virtually all real-world globs.

Why is the dot escaped in the output?

In a glob the dot is a literal character, but in a regex the dot matches anything. The converter escapes it to \. so the regex keeps the glob meaning.

Can I use the regex in any language?

The output uses standard syntax that works in JavaScript, Python, PCRE, Go, and most engines. Anchoring and the non-capturing group are universally supported.