Glob pattern to regex converter
Paste a glob and get the matching regular expression: *.js becomes ^.*\.js$, with the dot escaped so it only matches a real dot. Brackets, question marks and backslash escapes are translated too. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Pattern
- *.js
- Regex
- ^.*\.js$
- Regex body
- .*\.js
- Wildcard count
- 1
Shell glob patterns are the everyday language of filename filters: star for any run of characters, question mark for a single character, and bracket classes for a set or range. Regular expressions use a different, denser syntax, and developers constantly need a faithful translation when wiring a UI filter, a test harness, or a config file that only accepts regex. This glob pattern to regex converter accepts a shell-style pattern, walks it once character by character, maps each wildcard to its regex counterpart, escapes every literal that would otherwise be special in a regular expression, and returns a stable regex string plus a body without anchors when you need to embed the fragment. Optional path mode stops star and question mark from crossing slash so path-segment rules match how find and many shells behave.
How shell globs map to regular expressions
A shell glob is a compact pattern language designed for matching filenames, not for full text parsing. The star wildcard matches any sequence of characters (including the empty sequence); in this converter the default mapping is the regex construct dot-star, while path mode maps star to a character class that excludes slash followed by a star quantifier so a single star cannot swallow directory separators. The question mark matches exactly one character; default mode uses a single dot, and path mode uses a single non-slash character class.
Bracket expressions such as square-bracket a-z square-bracket or square-bracket abc square-bracket become the corresponding regex character class. Shell negation uses an exclamation mark immediately after the opening bracket, which this tool rewrites as a caret-negated class so engines that only know caret negation still work. A caret right after the opening bracket is also accepted as negation.
Backslash before a character forces that character to be treated as a literal even when it is star, question mark, or an opening bracket. Every ordinary character that is special in regular expressions—dot, plus, parentheses, braces, pipe, caret, dollar, and friends—is escaped so a literal filename fragment such as report.v2 does not accidentally mean report followed by any character followed by v2.
Brace expansion of the form curly a comma b curly is shell pre-processing, not glob matching, so braces stay literal characters in the output regex rather than becoming alternation groups.
When turning a glob into a regex helps
Frontend product filters often start as user-friendly globs (star for any suffix, question mark for a single placeholder) while the search index or database only accepts regular expressions; converting at the edge keeps the product language simple and the query engine correct. Test suites and CI scripts that accept include and exclude globs can compile those globs once into regex objects and reuse them across thousands of path checks without re-implementing shell rules ad hoc.
Security review and code search workflows sometimes need to show what a legacy glob actually means in regex form before approving a rule change. Failed validation does not consume balance. Keep patterns short, pin the returned regex strings in tests, and you get reproducible translations for widgets, SDKs, and edge workers without standing up a shell or a language-specific fnmatch library of your own.
What you can do with it
UI filters that speak glob, engines that need regex
Accept user-facing patterns like *.png or report-????.csv and compile them into anchored regexes for client-side or server-side matching.
Docs and teaching of wildcard semantics
Show side-by-side what a shell glob becomes as a regular expression so learners see escapes, classes, and anchors clearly.
FAQ
What wildcards are supported?
Star (*) for any sequence, question mark (?) for one character, bracket classes ([abc], [a-z], [! x] or [^x] for negation), and backslash escapes of the next character. Brace expansion is not treated as a wildcard.
Why is the dot in a file name escaped?
In a regular expression a plain dot means any character, so report.v2 would also match report followed by any character and v2. Every character that is special in regular expressions is escaped, so literal parts of a name stay literal.
What does path mode change?
With path mode on, a star and a question mark stop at a slash, so a single star cannot swallow folder separators, as with find and many shells. Without it, both may match any character, slashes included.
Are brace patterns such as {a,b} expanded?
No. Braces are a shell pre-processing step rather than glob matching, so they stay as literal characters in the regular expression instead of becoming a list of alternatives.
Can I get the expression without the start and end anchors?
Yes. By default the result is wrapped in ^ and $ so it matches the whole text, but you can also take the bare body, ready to embed inside a larger pattern.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/dev/glob-to-regex \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"pattern":"*.js"}'const res = await fetch("https://api.kit.forhosting.com/dev/glob-to-regex", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"pattern": "*.js"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/dev/glob-to-regex",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"pattern": "*.js"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/dev/glob-to-regex", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"pattern":"*.js"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"pattern":"*.js"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/dev/glob-to-regex", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"pattern": "*.js"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "dev.glob_to_regex",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Input fields, response shape, and failure modes
Character classes may include a literal closing bracket as the first member after the opener or the negation marker, matching common POSIX and shell practice. Trailing lone backslash is treated as a literal backslash rather than an incomplete escape. Send a JSON body with the required string field pattern (aliases glob, pattern_glob, wildcard) containing the shell glob you want translated. Optional boolean path_mode (default false) enables slash-aware star and question mark. Optional boolean anchored (default true) wraps the finished expression with caret and dollar so the regex matches an entire candidate string; set anchored to false when you only need the body for composition inside a larger pattern. On success the response echoes pattern, path_mode, and anchored; returns regex (the full expression you can feed to a regex engine); returns regex_body (the same translation without the outer anchors); reports wildcard_count so you can see how many star, question mark, or class tokens were found; and includes a short formula string summarizing the mapping in effect. Empty pattern, non-string pattern, patterns longer than two thousand forty-eight characters, unclosed character classes, empty classes, and inverted ranges such as z-a fail with invalid_input and are not billed.
Integration use cases
CI include and exclude rules
Translate project globs into path_mode regexes so test runners and linters apply the same segment-aware rules without re-parsing globs on every file.
Technical questions
How do I convert a glob pattern to a regular expression?
POST a JSON body with pattern set to your shell glob (for example *.js). The API returns regex (anchored by default) and regex_body. Set path_mode true if * and ? must not match slash.
What does path_mode change?
When path_mode is true, * becomes [^/]* and ? becomes [^/], so neither wildcard crosses a directory separator. When false (default), they may match any character including slash.
Why did I get invalid_input?
Common causes are a missing or empty pattern, an unclosed '[...]' class, an empty class, an inverted range inside brackets, a non-string pattern, or a pattern longer than 2048 characters. Those failures are not billed.
What does the glob pattern to regex converter cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.