https://github.com/psenger/globtoregex
Glob to RegEx - lightweight tool to convert Apache Glob for Unix to a Regular Expresion
https://github.com/psenger/globtoregex
Last synced: 6 months ago
JSON representation
Glob to RegEx - lightweight tool to convert Apache Glob for Unix to a Regular Expresion
- Host: GitHub
- URL: https://github.com/psenger/globtoregex
- Owner: psenger
- License: gpl-3.0
- Created: 2023-06-12T02:32:49.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-19T08:30:06.000Z (about 2 years ago)
- Last Synced: 2025-06-23T06:45:52.121Z (7 months ago)
- Language: JavaScript
- Size: 144 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# globtoregex
> Glob to RegEx - lightweight tool to convert Apache Glob for Unix to a Regular Expression
## About
I needed a lightweight `glob` to `regex` converter for a project. I couldn't find one that was light weight enough for my needs so I wrote one.
## Installation
`npm install @psenger/globtoregex --save`
or
`yarn add @psenger/globtoregex`
## Syntax
| Wildcard | Description | Example | Matches | Does not match |
|----------|-----------------------------------------------------|--------------|---------------------------------|----------------------------------|
| `*` | Matches any number of characters zero or more times | `*.txt` | `foo.txt`, `bar.txt`, `baz.txt` | `foo.txt.bak`, `foo.txt/bar.txt` |
| `?` | Matches any single character | `?.txt` | `a.txt`, `b.txt`, `c.txt` | `foo.txt`, `bar.txt`, `baz.txt` |
| `[abc]` | Matches any character in the set | `[abc].txt` | `a.txt`, `b.txt`, `c.txt` | `foo.txt`, `bar.txt`, `baz.txt` |
| `[a-z]` | Matches any character in the range | `[a-z].txt` | `a.txt`, `b.txt`, `c.txt` | `foo.txt`, `bar.txt`, `baz.txt` |
| `[!abc]` | Matches any character not in the set | `[!C]at` | `Bat`, `bat`, or `cat` | `Cat` |
| `[!a-z]` | Matches any character not in the range | `[!a-z].txt` | `A.txt`, `B.txt`, `C.txt` | `foo.txt`, `bar.txt`, `baz.txt` |