Glob to Regex Converter

Glob to Regex Converter

Convert shell-style glob patterns into JavaScript-compatible regex source with exact or partial matching and segment-aware wildcard handling. Perfect for file filters, build rules, route matching, and developer tooling.

glob
regex
converter
Share this tool:
Quick Presets
Glob patterns for conversion
Input
Enter a glob pattern to convert into a regular expression.
How it works: Converts glob patterns (like *.js or src/** /*.ts) to equivalent regular expression patterns with configurable matching behavior.

What is Glob to Regex Converter?

The Glob to Regex Converter translates shell-style wildcard patterns into JavaScript-compatible regular expression source. You enter a glob pattern like *.js or src/**/*.test.ts, and the tool outputs the equivalent regex that can be used with JavaScript's RegExp constructor. It supports *, ?, **, character classes, and brace alternatives.

How does Glob to Regex Converter work?

This tool converts glob syntax to regex by mapping * to [^/]* (match within a segment), ? to [^/] (match one character), and ** to .* (match across segments). Character classes like [abc] pass through unchanged. Brace alternatives like {js,ts} are expanded into regex alternation. The output is regex source without delimiters.

Key Features

  • Converts *, ?, **, character classes, and brace alternatives
  • Exact-match or partial-match output modes
  • Path-segment-aware or loose wildcard modes
  • Quick presets for common patterns
  • Copy regex source to clipboard
  • Maps *, ?, **, character classes, and brace expansions
  • Real-time conversion
  • Handles complex nested patterns

Common Use Cases

When and why you might need this tool
  • Converting build tool file patterns

    Translate glob patterns from webpack, Vite, or rollup configs into regex for custom scripts.

  • Creating route matching patterns

    Convert path globs like /api/** to regex for use in a JavaScript router.

  • Filtering files in Node.js scripts

    Turn shell-style include/exclude globs into regex for filtering directory listings.

  • Migrating patterns between tools

    Convert globs from one tool's syntax to regex for use in a different tool that expects regex.

How to Use This Tool

Step-by-step guide to get the best results
1

Paste a glob pattern

Enter the glob you want to convert (e.g., src/**/*.test.ts).

2

Choose options

Select path-segment mode (strict) or loose mode, and exact-match or partial-match.

3

Convert

Click Convert. The tool generates the regex source.

4

Copy the regex

Copy the output for use in new RegExp() or pattern matching code.

Pro Tips

  • 1

    Use exact-match mode when the regex should match the entire input string.

  • 2

    Path-segment mode prevents * from crossing / boundaries, which is correct for file paths.

  • 3

    Test the generated regex with sample inputs before using it in production.

  • 4

    The output is regex source, not a RegExp object. Wrap it in /pattern/ or new RegExp().

Frequently Asked Questions

What is the difference between a glob and a regex?

glob to regex conversion turns a simple shell-style wildcard pattern into regex source for a more powerful pattern language.

Does it support recursive ** matching?

Yes. The ** pattern is converted to regex that spans across path segments, allowing recursive directory matching.

What is path-segment mode?

In path-segment mode, * and ? only match within a single slash-delimited segment. This is the correct behavior for file path patterns.

Can I use the output directly in JavaScript?

Yes. The output is regex source that you pass to new RegExp() or use with match() and test() methods.

Is my pattern sent to a server?

No. All conversion happens in your browser. Nothing is transmitted.