PHPackages                             weew/url-matcher - 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. weew/url-matcher

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

weew/url-matcher
================

Simple url matcher and parser.

v1.1.0(9y ago)150.7k↓50%22MITPHP

Since Jan 25Pushed 9y ago1 watchersCompare

[ Source](https://github.com/weew/url-matcher)[ Packagist](https://packagist.org/packages/weew/url-matcher)[ RSS](/packages/weew-url-matcher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (4)Used By (2)

Url matcher
===========

[](#url-matcher)

[![Build Status](https://camo.githubusercontent.com/38d966f19340a7e60d9b8c23a61785cadc1df7597a0627b558ee0d37c1b9e58c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f776565772f75726c2d6d6174636865722e737667)](https://travis-ci.org/weew/url-matcher)[![Code Quality](https://camo.githubusercontent.com/6874f1ad605b135c3f13cc28a3c0c1819ceec79b1c62380575fd4a8e490cf214/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776565772f75726c2d6d6174636865722e737667)](https://scrutinizer-ci.com/g/weew/url-matcher)[![Test Coverage](https://camo.githubusercontent.com/6b2aa3b360cd5f34b883459d6f3a5ae0ebf1f593ede078373885292e8aed1dd8/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f776565772f75726c2d6d6174636865722e737667)](https://coveralls.io/github/weew/url-matcher)[![Version](https://camo.githubusercontent.com/659624e4be7ee3d6d3b3af3a2155a0fdcfe9766b601d436efc70b73a4bb4f37a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776565772f75726c2d6d6174636865722e737667)](https://packagist.org/packages/weew/url-matcher)[![Licence](https://camo.githubusercontent.com/aa0b9732b8e90f9cc9a6ce29005b044707365a20c79a41d49b3a2595d210ecd9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776565772f75726c2d6d6174636865722e737667)](https://packagist.org/packages/weew/url-matcher)

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Introduction](#introduction)
- [Usage](#usage)
- [Matching](#matching)
- [Parsing](#parsing)
- [Replacing](#replacing)

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

[](#installation)

`composer require weew/url-matcher`

Introduction
------------

[](#introduction)

This this simple matcher allows you to match url like paths against patterns with placeholders and even extract them.

Usage
-----

[](#usage)

Creating a new matcher is very simple.

```
$matcher = new UrlMatcher();
```

### Matching

[](#matching)

Below is a very basic matching example.

```
// true
$matcher->match('users/{id}', 'users/1');

// false
$matcher->match('users/{id}', 'users');
```

Placeholders can be optional by adding `?` at the end.

```
// true
$matcher->match('users/{id?}', 'users/1');

// true
$matcher->match('users/{id?}', 'users');
```

Placeholders can have custom patterns.

```
$matcher->addPattern('id', '[0-9]+');

// true
$matcher->match('users/{id}', 'users/1');

// false
$matcher->match('users/{id}', 'users/abc');
```

You can provide patterns inline.

```
// true
$matcher->match('users/{id}', 'users/1', [
    'id' => '[0-9]+',
]);
```

Placeholders can be optional too.

```
// true
$matcher->match('users/{id?}', 'users/1', [
    'id' => '[0-9]+',
]);

// true
$matcher->match('users/{id?}', 'users', [
    'id' => '[0-9]+',
]);
```

### Parsing

[](#parsing)

Extracting placeholders is very trivial too. The `parse` method always returns an instance of `IDictionary`.

```
$dictionary = $matcher->parse('users/{id}', 'users/123');
// 123
$dictionary->get('id');

$dictionary = $matcher->parse('users/{id}', 'users');
// null
$dictionary->get('id');
```

Of course, placeholders can have custom patterns.

```
$matcher->addPattern('id', '[0-9]+');
$dictionary = $matcher->parse('users/{id}', 'users/123');
// 123
$dictionary->get('id');

$dictionary = $matcher->parse('users/{id}', 'users/abc');
// null
$dictionary->get('id');
```

### Replacing

[](#replacing)

You can do the opposite of parsing by replacing placeholders with specific values.

```
// api.service.com
$matcher->replace('{subdomain}.service.com', 'subdomain', 'api');

// api.service.com/v1
$matcher->replaceAll('{subdomain}.service.com/{version}', ['subdomain' => 'api', 'version' => 'v1']);
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

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 ~91 days

Total

3

Last Release

3584d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/10b2b854b5829dd13a15967c000ed2119b5faef67aca24d94c653c8ac550d85e?d=identicon)[weew](/maintainers/weew)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/weew-url-matcher/health.svg)

```
[![Health](https://phpackages.com/badges/weew-url-matcher/health.svg)](https://phpackages.com/packages/weew-url-matcher)
```

PHPackages © 2026

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