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.
Complete Guide: Glob to Regex Converter
Everything you need to know about using this tool effectively
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.
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.
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.
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.
Use exact-match mode when the regex should match the entire input string.
Path-segment mode prevents * from crossing / boundaries, which is correct for file paths.
Test the generated regex with sample inputs before using it in production.
The output is regex source, not a RegExp object. Wrap it in /pattern/ or new RegExp().
What is the difference between a glob and a regex?
A glob is a simple wildcard pattern used in shells and file tools. A regex is a more powerful pattern language. This tool bridges the two by converting glob syntax into regex source.
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.