PHPackages                             nick-jones/globby - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nick-jones/globby

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nick-jones/globby
=================

Glob wildcard → regular expression translation library

v0.3.0(11y ago)245MITPHPPHP &gt;=5.5

Since Feb 5Pushed 10y ago2 watchersCompare

[ Source](https://github.com/nick-jones/globby)[ Packagist](https://packagist.org/packages/nick-jones/globby)[ RSS](/packages/nick-jones-globby/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (14)Used By (0)

Globby
======

[](#globby)

[![Build Status](https://camo.githubusercontent.com/6adebcb2b68e05ea714634d8d2f0d385f33625cf80e6ba37d637bcd369bc0ae5/68747470733a2f2f7472617669732d63692e6f72672f6e69636b2d6a6f6e65732f676c6f6262792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/nick-jones/globby) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/31f02feda665c379ba21818d5812bf8a87eda70f750c57de50b9a79470132830/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e69636b2d6a6f6e65732f476c6f6262792f6261646765732f7175616c6974792d73636f72652e706e673f733d66613839623935373563353061396533333461353839346234323562646331326338356661343534)](https://scrutinizer-ci.com/g/nick-jones/Globby/) [![Code Coverage](https://camo.githubusercontent.com/3fcf416f418af8aa280e1d20cdee55a4e38828552ccfcfabb214f9d894299143/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e69636b2d6a6f6e65732f476c6f6262792f6261646765732f636f7665726167652e706e673f733d32303938393361353166356161313734376562323432363564373936343035653866343839303364)](https://scrutinizer-ci.com/g/nick-jones/Globby/) [![HHVM Status](https://camo.githubusercontent.com/fcba10e7bdd833956ed719f40a89daf0d532388df3f56dd4e3d81a73bb9e8757/687474703a2f2f6868766d2e683463632e64652f62616467652f6e69636b2d6a6f6e65732f676c6f6262792e737667)](http://hhvm.h4cc.de/package/nick-jones/globby)

Globby is a glob wildcard → regular expression translation library.

Before you endeavour on using this, do note that this is probably *not* what you want. Glob wildcard patterns are extremely close to regex patterns; as such, if you wish to use pattern matching in your application, you are far better off using [`preg_match()`](http://php.net/preg_match). Also note that if you wish to pattern match file paths, then do of course use [`glob()`](http://php.net/glob), [`GlobIterator`](http://php.net/globiterator), or [`fnmatch()`](http://php.net/fnmatch).

If you do have one of the limited set of use-cases this library can cater for, then please continue reading..

About
-----

[](#about)

Globby is able to compile glob wildcard patterns into regular expressions. The following features are supported:

- Multi-character wildcard (`*`)
- Single-character wildcard (`?`)
- Character groups/classes (`[abc]`)
- Negated character groups/classes (`[!abc]`, `[^abc]`)
- Character ranges (`a-z`, `0-9`, etc)
- POSIX character classes (`[:alpha:]`, `[:digit:]`, etc)
- Escape character (`\`)

It lacks support for collating symbols (e.g. `[.ch.]`) and equivalence class expressions (e.g. `[=a=]`).

Unlike many glob pattern → regex translation solutions, Globby does not perform naïve replacements on the pattern. The translation process involves lexing the supplied pattern with [Phlexy](https://github.com/nikic/Phlexy), and then building a regular expression based on the token output.

Warnings
--------

[](#warnings)

The glob pattern → regex translation process is slow, and intensive. So it's worth reminding at this stage, you probably want [`preg_match()`](http://php.net/preg_match) instead.

The compile stage only occurs once for any given instance, so you perhaps need not worry so much for long running applications working with a fixed set of patterns; the initial compiles will be intensive, but further matches will utilise the cached regular expression.

If you were to use this in short-running applications (e.g. web applications), then you'd be well advised to wrap or extend `Pattern` with an implementation that caches the glob pattern → regex translations, such as to avoid the compile step on every relevant request (this is assuming the patterns are reasonably fixed.)

Installation
------------

[](#installation)

You can install Globby via [composer](http://getcomposer.org):

`composer require nick-jones/globby`

Usage
-----

[](#usage)

Simply create an instance of `\Globby\Pattern`, supplying the pattern in the constructor. The `toRegex()` method will give you the regular expression equivalent of the pattern. An example:

```
$pattern = new \Globby\Pattern('wow\[such\]?pat\*ter[nr][!,]!*wild[[:digit:]]');
var_dump($pattern->toRegex());
// result: string(48) "#^wow\[such\].pat\*ter[nr][^,]\!.*wild[[:digit:]]$#u"
```

For your convenience, the interface also provides a `match($value)` method that plugs the regular expression straight into preg\_match, indicating whether or not the supplied value matches the pattern. An example:

```
$pattern = new \Globby\Pattern('wow\[such\]?pat\*ter[nr][!,]!*wild[[:digit:]]');
var_dump($pattern->match('wow[such]:pat*tern.!much.wild9'));
// result: bool(true)
```

If the supplied pattern is invalid, you are likely to encounter a `TokenizeException`. This can happen, for example, if a character grouping remains open:

```
$pattern = new \Globby\Pattern('[abc'); // should have been closed with an "]"
// result: exception 'Globby\Tokenizer\TokenizeException' with message 'Premature end of pattern'
```

Tests
-----

[](#tests)

The unit and integration tests for Globby are built with PHPUnit. These are located within the [`test/unit/`](test/unit)and [`test/integration/`](test/integration) directories respectively. These tests are configured by [`phpunit.xml`](phpunit.xml) within the project root.

PHPUnit is listed as a development dependency for this project; as such, you can simply run `./vendor/bin/phpunit`to execute the tests.

A simple functional test suite is also provided, refer to [`test/functional/`](test/functional/) for further information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~31 days

Recently: every ~76 days

Total

13

Last Release

4100d ago

PHP version history (2 changes)v0.1PHP &gt;=5.3

v0.3.0PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/759dcc9fc48dd4d80afbca495caef56504bcbe4a69ff696ab16e7f1fe57a74c5?d=identicon)[nick-jones](/maintainers/nick-jones)

---

Top Contributors

[![nick-jones](https://avatars.githubusercontent.com/u/350792?v=4)](https://github.com/nick-jones "nick-jones (59 commits)")

---

Tags

globpatternMatchwildcard

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nick-jones-globby/health.svg)

```
[![Health](https://phpackages.com/badges/nick-jones-globby/health.svg)](https://phpackages.com/packages/nick-jones-globby)
```

###  Alternatives

[league/pipeline

A plug and play pipeline implementation.

1.0k16.0M74](/packages/league-pipeline)[longman/ip-tools

PHP IP Tools for manipulation with IPv4 and IPv6

147245.6k6](/packages/longman-ip-tools)[getsolaris/laravel-make-service

A MVCS pattern create a service command for Laravel 5+

81161.3k](/packages/getsolaris-laravel-make-service)[redeyeventures/geopattern

Generate beautiful SVG patterns.

11140.8k2](/packages/redeyeventures-geopattern)[functional-php/pattern-matching

Pattern matching for PHP with automatic destructuring.

8261.5k](/packages/functional-php-pattern-matching)[lezhnev74/pasvl

Array Validator (regular expressions for nested array, sort of)

5253.7k3](/packages/lezhnev74-pasvl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
