Categories

Glob to Regex

Convert file matching patterns (Glob) to regular expressions

Convert Glob patterns like src/**/*.ts to standard regular expressions. Useful for understanding Glob patterns and creating custom file matching logic.

Support brace expansion like {a,b,c}

Support ** for recursive directory matching

Match regardless of case

One string per line. Results will show which strings match.

Key Facts

Category
Development
Input Types
text, checkbox, textarea
Output Type
json
Sample Coverage
4
API Ready
Yes

Overview

This tool converts file matching patterns known as Glob into standard regular expressions. It supports features like brace expansion and recursive directory matching, enabling developers to create custom file matching logic for various programming contexts.

When to Use

  • When you need to use Glob patterns in systems or tools that require regular expressions for file matching.
  • To understand or debug complex Glob patterns by viewing their equivalent regex representation.
  • For building file filtering features in applications that only support regex-based matching.

How It Works

  • Enter a Glob pattern, such as 'src/**/*.ts', into the input field.
  • Configure options like enabling extended mode for brace expansion or globstar for recursive '**' support.
  • Optionally, add test strings to verify which paths the generated regex will match.
  • The tool outputs the corresponding regular expression ready for use in code or scripts.

Use Cases

Integrating file matching in build tools or automation scripts that rely on regular expressions.
Creating custom ignore patterns for version control systems or file watchers that use regex.
Developing file search functionality in desktop or web applications requiring pattern-based filtering.

Examples

1. Convert Basic Glob Pattern

Background
A developer needs to match all TypeScript files in a source directory for a build process.
Problem
The build system requires a regular expression, but the file pattern is specified in Glob format.
How to Use
Enter 'src/**/*.ts' in the Glob Pattern field and ensure globstar support is enabled.
Outcome
The tool outputs a regex that matches files like 'src/app/index.ts' and 'src/lib/utils.ts'.

2. Handle Brace Expansion

DevOps Engineer
Background
Setting up a deployment script that processes configuration files with multiple extensions.
Problem
Need to convert a Glob pattern with braces to a regex for script integration.
How to Use
Input 'config/*.{json,yaml}' and check the Extended Mode option.
Example Config
Extended mode enabled.
Outcome
The generated regex matches both 'config/app.json' and 'config/settings.yaml' files.

3. Test Recursive Matching

Background
Verifying that a Glob pattern correctly matches files in nested directories for a file search feature.
Problem
Ensure the '**' wildcard works as expected in the regex conversion before implementation.
How to Use
Enter 'src/**/test*.js', enable globstar support, and add test strings like 'src/app/test.js' and 'src/lib/utils/test.js'.
Outcome
The regex matches all test files in any subdirectory under 'src', and test results confirm the matches are accurate.

Try with Samples

text, regex

Related Hubs

FAQ

What is a Glob pattern?

A Glob pattern is a string used for matching file paths, employing wildcards like '*' for any characters and '?' for a single character.

How does extended mode affect the conversion?

Extended mode allows brace expansion, converting patterns like '{a,b}' into regex alternations for matching multiple options.

Can I test the regex with sample strings?

Yes, use the test strings field to input file paths and see which ones match the generated regex in real-time.

Is the output regex case-sensitive?

By default, the regex is case-sensitive, but you can enable the case-insensitive option to match regardless of letter case.

What does globstar support do?

Globstar support enables the '**' wildcard to match directories recursively, allowing patterns to traverse nested folders.

API Documentation

Request Endpoint

POST /en/api/tools/glob-to-regex

Request Parameters

Parameter Name Type Required Description
globPattern text Yes -
extended checkbox No Support brace expansion like {a,b,c}
globstar checkbox No Support ** for recursive directory matching
caseInsensitive checkbox No Match regardless of case
testString textarea No One string per line. Results will show which strings match.

Response Format

{
  "key": {...},
  "metadata": {
    "key": "value"
  },
  "error": "Error message (optional)",
  "message": "Notification message (optional)"
}
JSON Data: JSON Data

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-glob-to-regex": {
      "name": "glob-to-regex",
      "description": "Convert file matching patterns (Glob) to regular expressions",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=glob-to-regex",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]