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.
Continue Your Code Journey
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
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
Paste a glob pattern
Enter the glob you want to convert (e.g., src/**/*.test.ts).
Choose options
Select path-segment mode (strict) or loose mode, and exact-match or partial-match.
Convert
Click Convert. The tool generates the regex source.
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.