PHPackages                             phlak/glob - 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. phlak/glob

Abandoned → [phlak/splat](/?search=phlak%2Fsplat)Library[Utility &amp; Helpers](/categories/utility)

phlak/glob
==========

Glob-like pattern matching and utilities

6.0.0(1y ago)105245[3 PRs](https://github.com/PHLAK/Splat/pulls)MITPHPPHP &gt;=8.1CI passing

Since May 1Pushed 1y ago2 watchersCompare

[ Source](https://github.com/PHLAK/Splat)[ Packagist](https://packagist.org/packages/phlak/glob)[ GitHub Sponsors](https://github.com/sponsors/PHLAK)[ Fund](https://paypal.me/ChrisKankiewicz)[ RSS](/packages/phlak-glob/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (10)Dependencies (7)Versions (20)Used By (0)

 [![Splat](splat.svg)](splat.svg)

 [![Join our Community](https://camo.githubusercontent.com/073a08ec4c3c801a8e24c53184d95a6562d74582854cb46320bcd76ef48ea543/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4a6f696e5f7468652d436f6d6d756e6974792d3762313666662e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/PHLAK/Splat/discussions) [![Become a Sponsor](https://camo.githubusercontent.com/00da07edf5fbff7528a4743d85563603f9284f02680e0ab1e73652e680878548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4265636f6d655f612d53706f6e736f722d6363343139352e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/users/PHLAK/sponsorship) [![One-time Donation](https://camo.githubusercontent.com/e9b5aa71ffdb17943c10c6d6b4a3132b66a938495331e488ecbdad1f3c078879/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d616b655f612d446f6e6174696f6e2d3030366262362e7376673f7374796c653d666f722d7468652d6261646765)](https://paypal.me/ChrisKankiewicz)
 [![Latest Stable Version](https://camo.githubusercontent.com/695e3b316dac17fbe33f8395dfe45037207873af5cf41731188bc63ddaa0b435/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f50484c414b2f53706c61742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/Splat) [![Total Downloads](https://camo.githubusercontent.com/af057d250ff0cda8d703cfcbd90647c263aa430f008c64d6a425cdb45b25d310/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f50484c414b2f53706c61742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/Splat) [![License](https://camo.githubusercontent.com/93829c5ff10697233648a69dcfeafffe987c8b8c0db054512c8b16e5c6b2e2fe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f50484c414b2f53706c61743f7374796c653d666c61742d737175617265)](https://github.com/PHLAK/Splat/blob/master/LICENSE) [![Tests Status](https://camo.githubusercontent.com/2d2107c81c12baba44a36e20ca7942e4d379f8005f380c653fc970aefe9a0038/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f50484c414b2f53706c61742f746573742d73756974652e79616d6c3f7374796c653d666c61742d737175617265266c6162656c3d7465737473)](https://github.com/PHLAK/Splat/actions)

---

Glob-like file and pattern matching utility.

Requirements
------------

[](#requirements)

- [PHP](https://www.php.net/) &gt;= 8.1

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

[](#installation)

Install Splat with Composer.

```
composer require phlak/splat

```

Then import the `Glob` or `Pattern` classes as needed.

```
use PHLAK\Splat\Glob;
use PHLAK\Splat\Pattern;
```

Patterns
--------

[](#patterns)

`Glob` methods accept a `$pattern` as the first parameter. This can be a string or an instance of `\PHLAK\Splat\Pattern`.

```
$pattern = new Pattern(...);
$pattern = Pattern::make(...);
```

A pattern string may contain one or more of the following special matching expressions.

### Matching Expressions

[](#matching-expressions)

- `?` matches any single character
- `*` matches zero or more characters excluding `/` (`\` on Windows)
- `**` matches zero or more characters including `/` (`\` on Windows)
- `[abc]` matches a single character from the set (i.e. `a`, `b` or `c`)
- `[a-c]` matches a single character in the range (i.e. `a`, `b` or `c`)
- `[!abc]` matches any character not in the set (i.e. not `a`, `b` or `c`)
- `[!a-c]` matches any character not in the range (i.e. not `a`, `b` or `c`)
- `{foo,bar,baz}` matches any pattern in the set (i.e. `foo`, `bar` or `baz`)
    - Sets may contain other matching patterns (i.e. `{foo,ba[rz]}`)

### Assertions

[](#assertions)

The following assertions can be use to assert that a string is followed by, or not followed by, another pattern.

- `(=foo)` matches any string that also contains `foo`
- `(!foo)` matches any string that does not also contain `foo`

For example, a pattern of `*.tar(!.{gz,xz})` will match a string ending with `.tar` or `.tar.bz` but not `tar.gz` or `tar.xz`.

### Converting Patterns To Regular Expressions

[](#converting-patterns-to-regular-expressions)

Glob patterns can be converted to a regular expression pattern.

```
Pattern::make('foo')->toRegex(); // Returns '#^foo$#'
Pattern::make('foo/bar.txt')->toRegex(); // Returns '#^foo/bar\.txt$#'
Pattern::make('file.{yml,yaml}')->toRegex(); // Returns '#^file\.(yml|yaml)$#'
```

You can control regular expression line anchors via the `$anchors` parameter.

```
use PHLAK\Splat\Anchors;
use PHLAK\Splat\Pattern;

Pattern::make('foo')->toRegex(Anchors::NONE); // Returns '#foo#'
Pattern::make('foo')->toRegex(Anchors::START); // Returns '#^foo#'
Pattern::make('foo')->toRegex(Anchors::END); // Returns '#foo$#'
Pattern::make('foo')->toRegex(Anchors::BOTH); // Returns '#^foo$#'
```

### Pattern Character Escaping

[](#pattern-character-escaping)

Sometimes you may have characters in a string that shouldn't be treated as matching expression characters. In those situations you can escape any character by preceeding it with a backslash (`\`).

```
Pattern::make('What is happening\?');
Pattern::make('Wall-E \[2008\].mp4');
```

You may also escape glob pattern characters from a string programmatically with the `Pattern::escape()` method.

```
Pattern::escape('What is happening?'); // Returns 'What is happening\?'
Pattern::escape('*.{yml,yaml}'); // Returns '\*.\{yml\,yaml\}'
Pattern::escape('[Ss]pl*t.txt'); // Returns '\[Ss\]pl\*t.txt'
```

Methods
-------

[](#methods)

### Files In

[](#files-in)

Get a list of files in a directory matching a glob pattern.

```
Glob::in('**.txt', 'some/file/path');
```

Returns a [Symfony Finder Component](https://symfony.com/doc/current/components/finder.html)containing the files matching the glob pattern within the specified directory (e.g. `foo.txt`, `foo/bar.txt`, `foo/bar/baz.txt`, etc.).

---

### Exact Match

[](#exact-match)

Test if a string matches a glob pattern.

```
Glob::match('*.txt', 'foo.txt'); // true
Glob::match('*.txt', 'foo.log'); // false
```

---

### Match Start

[](#match-start)

Test if a string starts with a glob pattern.

```
Glob::matchStart('foo/*', 'foo/bar.txt'); // true
Glob::matchStart('foo/*', 'bar/foo.txt'); // false
```

---

### Match End

[](#match-end)

Test if a string ends with a glob pattern.

```
Glob::matchEnd('**.txt', 'foo/bar.txt'); // true
Glob::matchEnd('**.txt', 'foo/bar.log'); // false
```

---

### Match Within

[](#match-within)

Test if a string contains a glob pattern.

```
Glob::matchWithin('bar', 'foo/bar/baz.txt'); // true
Glob::matchWithin('bar', 'foo/baz/qux.txt'); // false
```

---

### Filter an Array (of Strings)

[](#filter-an-array-of-strings)

Filter an array of strings to values matching a glob pattern.

```
Glob::filter('**.txt', [
    'foo', 'foo.txt', 'bar.zip', 'foo/bar.png', 'foo/bar.txt',
]);

// Returns ['foo.txt', 'foo/bar.txt']
```

---

### Reject an Array (of Strings)

[](#reject-an-array-of-strings)

Filter an array of strings to values *not* matching a glob pattern.

```
Glob::reject('**.txt', [
    'foo', 'foo.txt', 'bar.zip', 'foo/bar.png', 'foo/bar.txt',
]);

// Returns ['foo', 'bar.zip', 'foo/bar.png']
```

Changelog
---------

[](#changelog)

A list of changes can be found on the [GitHub Releases](https://github.com/PHLAK/Splat/releases) page.

Troubleshooting
---------------

[](#troubleshooting)

For general help and support join our [GitHub Discussion](https://github.com/PHLAK/Splat/discussions) or reach out on [Bluesky](https://bsky.app/profile/phlak.dev).

Please report bugs to the [GitHub Issue Tracker](https://github.com/PHLAK/Splat/issues).

Copyright
---------

[](#copyright)

This project is licensed under the [MIT License](https://github.com/PHLAK/Splat/blob/master/LICENSE).

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance42

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 89.3% 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 ~167 days

Recently: every ~324 days

Total

11

Last Release

528d ago

Major Versions

1.0.0 → 2.0.02020-05-07

2.1.0 → 3.0.02020-05-15

3.1.0 → 4.0.02021-05-17

4.0.1 → 5.0.02023-03-27

5.0.1 → 6.0.02024-12-06

PHP version history (4 changes)0.1.0PHP &gt;=7.0

3.0.0PHP &gt;=7.2

5.0.0PHP &gt;=8.0

6.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/53531?v=4)[Chris Kankiewicz](/maintainers/PHLAK)[@PHLAK](https://github.com/PHLAK)

---

Top Contributors

[![PHLAK](https://avatars.githubusercontent.com/u/53531?v=4)](https://github.com/PHLAK "PHLAK (75 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![johanvanhelden](https://avatars.githubusercontent.com/u/19389981?v=4)](https://github.com/johanvanhelden "johanvanhelden (2 commits)")[![schakko](https://avatars.githubusercontent.com/u/359812?v=4)](https://github.com/schakko "schakko (2 commits)")[![vlakoff](https://avatars.githubusercontent.com/u/544424?v=4)](https://github.com/vlakoff "vlakoff (2 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")

---

Tags

file-matchingglobpattern-matchingphpregexregular-expression

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phlak-glob/health.svg)

```
[![Health](https://phpackages.com/badges/phlak-glob/health.svg)](https://phpackages.com/packages/phlak-glob)
```

###  Alternatives

[wnx/laravel-stats

Get insights about your Laravel Project

1.8k1.8M7](/packages/wnx-laravel-stats)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4723.6M20](/packages/coenjacobs-mozart)[illuminate/session

The Illuminate Session package.

9937.4M753](/packages/illuminate-session)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)

PHPackages © 2026

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