Glob to Regex Converter

Convert a glob pattern to a JavaScript regular expression in your browser and test it against real paths. Your patterns stay on your device.

Your glob pattern and the sample paths you test are converted locally in your browser and are never uploaded.

Built and maintained by Udit Agarwal

Need to debug the result? Open the Regex Tester.

About Glob to Regex

This glob to regex converter turns a shell-style wildcard pattern into an equivalent JavaScript regular expression you can drop straight into code. Type a glob such as *.js, **/*.ts, src/** or file-{a,b}.txt and the tool builds the regex source plus flags, escaping literal characters like dots and parentheses so they match exactly. Toggle globstar so ** crosses path separators, brace expansion for {a,b,c} alternation, full-string anchoring with ^ and $, and a case-insensitive flag. A live tester runs your regex against a list of sample paths, marking each match in green and each miss in red, and a legend explains every translated token. Everything runs in your browser, so the patterns and paths you enter stay on your device.

Features

  • Translates *, ?, ** (globstar), character classes and {a,b} braces into regex syntax
  • Globstar toggle controls whether ** and * cross the / path separator
  • Negated classes [!abc] become [^abc], and ranges like [0-9] are preserved
  • Escapes regex metacharacters that are literal in globs, so . + ( ) match exactly
  • Optional ^…$ anchoring for full-string matches and a case-insensitive i flag
  • Live tester checks a list of sample paths and colours each match green or red
  • Token legend explains what every part of the glob became in the regex
  • Copy the regex as a /pattern/flags literal with one click

How to use the Glob to Regex

  1. Type or paste a glob pattern such as **/*.ts into the pattern box.
  2. Switch globstar, anchoring, brace expansion and case-insensitivity on or off.
  3. Read the generated regex source and flags, and review the token legend.
  4. Enter sample paths in the tester, one per line, to see which match.
  5. Click Copy regex to grab the /pattern/flags literal for your code.

Example

Input

src/**/*.{ts,tsx}

Output

/^src/(?:.*/)?[^/]*\.(?:ts|tsx)$/

Globstar lets src/**/ span nested folders while *.{ts,tsx} stays at the leaf.

Common errors & troubleshooting

  • *.js unexpectedly matches a nested path like src/app.js. — Keep globstar on so a single * stops at the / separator; use **/*.js when you want nested files.
  • A pattern like file.txt matches filextxt or fileXtxt. — That happens with a raw regex; this converter already escapes the dot to \. so it only matches a literal period.
  • The regex never matches even though the path looks right. — Anchoring wraps the pattern in ^…$, so the whole string must match. Turn anchoring off for substring matching.
  • {a,b} shows up literally in the output instead of becoming an alternation. — Enable brace expansion; with it off, braces are treated as literal characters.

Frequently asked questions

What does ** mean in a glob pattern?
** is the globstar. With the globstar option on it matches across path separators, so src/**/*.ts reaches files in any nested folder, whereas a single * stops at the next /.
How are glob character classes converted to regex?
[abc] maps straight to a regex character class, ranges like [0-9] are kept intact, and a negated glob class written [!abc] is converted to [^abc] so it matches any character not listed.
Why does the converter escape dots and other characters?
Characters such as . + ( ) | are literal in a glob but special in a regex. The tool escapes them to \. \+ and so on, so the resulting regex matches those characters exactly instead of as operators.
Does it support brace expansion like {a,b,c}?
Yes. With brace expansion enabled, file-{a,b}.txt becomes an alternation that matches file-a.txt or file-b.txt, and you can even nest globs inside braces, such as {*.js,*.ts}.
Can I match a substring instead of the whole path?
Turn off full-string anchoring. Anchored patterns are wrapped in ^…$ so the entire string must match; without anchoring the regex can match anywhere inside a longer string.
Is my glob pattern sent to a server?
No. The glob to regex conversion and the live tester both run entirely in your browser, so the patterns and sample paths you type are processed locally and stay on your device.

Related tools

  • Regex Tester — Test regular expressions live with matches, groups and flags.
  • Text Diff — Compare two texts line-by-line and see additions and removals.
  • .gitignore Generator — Build a .gitignore from common language and tool templates.
  • Case Converter — Convert text between camelCase, snake_case, kebab-case, PascalCase and more.
  • HTML Escape / Unescape — Escape and unescape HTML special characters and entities.

Guides

More Code Formatters tools

  • HTML to Markdown — Paste HTML and convert it to clean Markdown live, with GFM tables, lists and code blocks.
  • TOML Formatter & Converter — Format and validate TOML, and convert TOML ↔ JSON.
  • logfmt to JSON — Convert logfmt key=value logs to JSON and back.
  • dotenv to JSON — Convert a .env file to JSON and JSON back to .env, with quoting and comments handled.
  • CSV to Markdown Table — Convert CSV or TSV data into a Markdown table, with alignment and header options.
  • INI to JSON — Convert INI config files to JSON and JSON back to INI, with sections and comments.
  • Markdown Table Generator — Build a table in an editable grid and export Markdown, HTML, AsciiDoc and LaTeX.
  • Data Size Converter — Convert between bits, bytes, KB, MB, GB and KiB, MiB, GiB, with decimal and binary units.
  • Java Properties ↔ JSON — Convert Java .properties files to JSON and JSON back to .properties, in your browser.
  • YAML ↔ JSON — Convert YAML to JSON and back.
  • Markdown Preview — Render Markdown to HTML with a live preview.
  • Regex Tester — Test regular expressions live with matches, groups and flags.

See all Code Formatters tools (32) · All tools