2017 © Pedro PelΓ‘ez
 

library globby

Glob wildcard β†’ regular expression translation library

image

nick-jones/globby

Glob wildcard β†’ regular expression translation library

  • Friday, September 25, 2015
  • by nick-jones
  • Repository
  • 2 Watchers
  • 1 Stars
  • 36 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 14 Versions
  • 0 % Grown

The README.md

Globby

Build Status Scrutinizer Code Quality Code Coverage HHVM Status, (*1)

Globby is a glob wildcard β†’ regular expression translation library., (*2)

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(). Also note that if you wish to pattern match file paths, then do of course use glob(), GlobIterator, or fnmatch()., (*3)

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

About

Globby is able to compile glob wildcard patterns into regular expressions. The following features are supported:, (*5)

  • 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=])., (*6)

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, and then building a regular expression based on the token output., (*7)

Warnings

The glob pattern β†’ regex translation process is slow, and intensive. So it's worth reminding at this stage, you probably want preg_match() instead., (*8)

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., (*9)

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.), (*10)

Installation

You can install Globby via composer:, (*11)

composer require nick-jones/globby, (*12)

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:, (*13)

$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:, (*14)

$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:, (*15)

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

Tests

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

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

A simple functional test suite is also provided, refer to test/functional/ for further information., (*18)

The Versions

25/09 2015

dev-master

9999999-dev

Glob wildcard β†’ regular expression translation library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Jones

pattern match glob wildcard

21/02 2015

v0.3.0

0.3.0.0

Glob wildcard β†’ regular expression translation library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Jones

pattern match glob wildcard

23/10 2014

v0.2.9

0.2.9.0

Glob wildcard β†’ regular expression translation library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Jones

pattern match glob wildcard

10/10 2014

v0.2.8

0.2.8.0

Glob wildcard β†’ regular expression translation library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Jones

pattern match glob wildcard

27/04 2014

v0.2.7

0.2.7.0

Glob wildcard β†’ regular expression translation library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Jones

pattern match glob wildcard

20/04 2014

v0.2.6

0.2.6.0

Glob wildcard β†’ regular expression translation library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Jones

pattern match glob wildcard

11/03 2014

v0.2.5

0.2.5.0

Glob wildcard β†’ regular expression translation library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Jones

pattern match glob wildcard

07/02 2014

v0.2.4

0.2.4.0

Glob wildcard β†’ regular expression translation library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Jones

pattern match glob wildcard

06/02 2014

v0.2.3

0.2.3.0

Wildcard library, providing glob wildcard pattern matching

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Jones

pattern glob wildcard

06/02 2014

v0.2.2

0.2.2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Jones

06/02 2014

v0.2.1

0.2.1.0

  Sources   Download

The Requires

 

The Development Requires

by Nicholas Jones

06/02 2014

v0.2

0.2.0.0

  Sources   Download

The Requires

 

The Development Requires

by Nicholas Jones

05/02 2014

v0.1.1

0.1.1.0

  Sources   Download

The Requires

 

The Development Requires

by Nicholas Jones

05/02 2014

v0.1

0.1.0.0

  Sources   Download

The Requires

 

The Development Requires

by Nicholas Jones