PHPackages                             selvinortiz/flux - 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. selvinortiz/flux

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

selvinortiz/flux
================

Fluent regular expressions in PHP.

v0.5.3(10y ago)3372.0k↓100%18[1 issues](https://github.com/selvinortiz/flux/issues)1MITPHPPHP &gt;=5.3.0

Since Jul 23Pushed 5y ago12 watchersCompare

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

READMEChangelog (2)DependenciesVersions (6)Used By (1)

FLUX (Fluent Regex) 0.5.2
-------------------------

[](#flux-fluent-regex-052)

[![Build Status](https://camo.githubusercontent.com/cbc331d6c200c80b72e72421d29b8a0ef2a6d753d8529ed109ef24a8bffebc9a/68747470733a2f2f7472617669732d63692e6f72672f73656c76696e6f7274697a2f666c75782e706e67)](https://travis-ci.org/selvinortiz/flux)[![Total Downloads](https://camo.githubusercontent.com/f32e7403a6b5247a046011f19bae00645247045cfacf1267d8666b1371c8c830/68747470733a2f2f706f7365722e707567782e6f72672f73656c76696e6f7274697a2f666c75782f642f746f74616c2e706e67)](https://packagist.org/packages/selvinortiz/flux)[![Latest Stable Version](https://camo.githubusercontent.com/53f96b8d77d84fce1970e90ec87bcecdd892e8b224984dd5a5b6cf94619de8d3/68747470733a2f2f706f7365722e707567782e6f72672f73656c76696e6f7274697a2f666c75782f762f737461626c652e706e67)](https://packagist.org/packages/selvinortiz/flux)

*by* [Selvin Ortiz](http://twitter.com/selvinortiz)

### Description

[](#description)

Fluent Regular Expressions *in* PHP inspired by and largely based on [VerbalExpressions:JS](https://github.com/jehna/VerbalExpressions) by [Jesse Luoto](https://plus.google.com/u/0/101155583332851062944/posts)

*@see inspiration &amp; credits below for more info.*

### Requirements

[](#requirements)

- PHP 5.3
- Composer

### Install

[](#install)

`Flux` is available as a [package](https://packagist.org/packages/selvinortiz/flux) via [composer](http://getcomposer.org)

- require: `"selvinortiz/flux": "dev-master"`
- autoload: `require_once 'path/to/vendor/autoload.php'`
- namespace: `use SelvinOrtiz\Utils\Flux\Flux;`
- instantiate: `$flux = Flux::getInstance();`

*You can additionally clone/download this repo and do whatever you want: )*

---

### @Example

[](#example)

This simple example illustrates the way you would use `flux` and it's fluent interface to build complex patterns.

```
require_once realpath(__DIR__.'/../vendor/autoload.php');

use SelvinOrtiz\Utils\Flux\Flux;
use SelvinOrtiz\Utils\Flux\Helper;

// The subject string (URL)
$str	= 'http://www.selvinortiz.com';

// Building the pattern (Fluently)
$flux	= Flux::getInstance()
		->startOfLine()
		->find('http')
		->maybe('s')
		->then('://')
		->maybe('www.')
		->anythingBut('.')
		->either('.co', '.com')
		->ignoreCase()
		->endOfLine();

// Output the Flux instance
Helper::dump( $flux );

// Output the fluently built pattern (@see /src/SelvinOrtiz/Utils/Flux/Helper)
Helper::msg( $flux ); // /^(http)(s)?(\:\/\/)(www\.)?([^\.]*)(.co|.com)$/i

// Inspect the results
Helper::msg( $str );
Helper::msg( $flux->match( $str ) ? 'matched' : 'unmatched' );
Helper::msg( $flux->replace( 'https://$5$6', $str ) );
```

*For other examples, please see the `/etc` directory.*

---

### @Changelog

[](#changelog)

---

#### 0.5.2

[](#052)

- Adds `length()` method which adds or replaces the modifier used in the previous call
- Adds `getLastSegmentKey()`
- Adds the (empty) `Factory` class for optimized, often used patterns
- Fixes indentation and EOF on `phpunit.xml`
- Fixes comment typos on `README` and example files [Pull Request #10](https://github.com/selvinortiz/flux/pull/10)

---

#### 0.5.1

[](#051)

- Adds `getSegments()` which was not included in `0.5.0` [Issue #5](https://github.com/selvinortiz/flux/issues/5)
- Adds `removeSegment()` which can be used in unit tests as well
- Adds `lineBreak()` and `br()` which matches a new line (DOS/Unix)
- Adds `clear()` which allows you to clear out the pattern and start from scratch
- Adds `getPattern()` which compiles the expression and returns it
- Adds `deprecation candidates as @todos
- Fixes mixed logic between `add()` and `raw()`
- Fixes implementation on the `orTry()` method
- Moves example in readme above `changelog`
- Improves unit tests

---

#### 0.5.0 (Beta)

[](#050-beta)

- Adds `getSegments()` to improve testability [Issue #5](https://github.com/selvinortiz/flux/issues/5)
- Adds composer package [selvinortiz/flux](https://packagist.org/packages/selvinortiz/flux)
- Adds `dev` branch
- Adds contributing notes
- Adds install notes

---

#### 0.4.5

[](#045)

- Fixes internal namespace conflict
- Changes namespace from `Sortiz\Tools` to `SelvinOrtiz\Utils\Flux`
- Adds composer support [Issue #3](https://github.com/selvinortiz/flux/issues/3)
- Adds the `addSeed()` and `removeSeed()` methods [Issue #4](https://github.com/selvinortiz/flux/issues/4)
- Adds the `getInstance()` static method
- Adds `FluxUrlExample.php`, `FluxDateExample.php`, and `FluxPhoneExample.php`
- Adds `getSeed()` to get the seed without forcing `__toString` on the object
- Adds `getSegment()` to extract a segment (capturing group) from the pattern
- Implements unit tests (60% coverage) [Issue #3](https://github.com/selvinortiz/flux/issues/3)
- Implements Full `PSR-2` Compliance (Tabs over Spaces)
- Enables the `seed` on `match()` and `replace()` [Issue #4](https://github.com/selvinortiz/flux/issues/4)
- Removes `example.php` and defines them elsewhere
- Moves examples into `/etc` and defines one example per file
- Other small fixes and additions

---

#### 0.4.0

[](#040)

- Adds `Flux` to the `Sortiz\Tools` namespace
- Implements `PSR-2` Compliance (Tabs over Spaces)
- Updates version number on `Flux` and this readme file
- Updates the class instantiation with fully qualified class name on `example.php`
- Adds references to other repos that have ported `flux`
- Addresses concerns outlined in [Issue #3](https://github.com/selvinortiz/flux/issues/3)

---

#### 0.3.0

[](#030)

- Improves documentation with `phone/date` examples
- Adds the `letters()` method
- Renames the `numbers()` method to `digits()`
- Adds support for quantifiers for `digits()`
- Adds `ignoreCase()` and promotes it above `inAnyCase()`
- Improves the documented API

*Thought hard about changing the name to `FluentX` any thoughts?*

---

#### 0.2.0

[](#020)

- Adds the `either( $option1, $option2 [, $option3 ...] )` method to handle OR cases
- Updates the *fluent* example in this readme file
- Adds the license

---

#### 0.1.0 (Alpha)

[](#010-alpha)

Initial preview release

---

### @Todo

[](#todo)

- Add source code comments
- Add support for quantifiers
- Add language methods for more advanced use cases
- Add reference to repos that have ported `Flux` (\*)
- Add license notes (\*)
- Add contributing notes (\*)
- Add credits (\*)

### FLUX API

[](#flux-api)

The **flux** API was designed to give you a *fluent chainable object* to build patterns with.

#### `startOfLine()`

[](#startofline)

Adds a beginning of line `^` modifier

#### `endOfLine()`

[](#endofline)

Adds an end of line `$` modifier

#### `find( $val ) & then( $val )`

[](#find-val---then-val-)

Allows you to augment the pattern with a required `segment` and it escapes regular expression characters

#### `maybe( $val )`

[](#maybe-val-)

Allows you to augment the pattern with an optional `segment`

#### `any( $val ) & anyOf( $val )`

[](#any-val---anyof-val-)

Allows you to create a set of characters to match

#### `anything()`

[](#anything)

Adds a *wild card* `(.*)` `segment` to the pattern but it does not make `dotAll()` explicit

#### `anythingBut( $val )`

[](#anythingbut-val-)

Will match anything but the characters in `$val` which is opposite of `any()` and `anyOf`

#### `br() & lineBreak()`

[](#br--linebreak)

Allows you to match a new line `(DOS/Unix)`

#### `tab()`

[](#tab)

Adds a `(\t)` to the pattern which will match a tab

#### `word()`

[](#word)

Adds `(\w+)` to the pattern which will match a single word

#### `letters( $min=null, $max=null )`

[](#letters-minnull-maxnull-)

Only matches characters in the alphabet and uses `$min` and `$max` to create a quantifier

#### `digits( $mix=null, $max=null )`

[](#digits-mixnull-maxnull-)

Only matches digits and uses `$min` and `$max` to create a quantifier like `word()`

#### `range( $from, $to [, $from, $to ...])`

[](#range-from-to--from-to-)

Allows you to create a `range` character class like `a-z0-9` by calling `range('a', 'z', 0, 9)`

#### `orTry( $val='' )`

[](#ortry-val-)

Allows you to create OR cases `(this)|(else)` and retain the capturing order to use in `replace()`

#### `ignoreCase() & inAnyCase()`

[](#ignorecase--inanycase)

Adds the `i` modifier to the pattern which will allow you to match in a case insensitive manner

#### `matchNewLine() & dotAll()`

[](#matchnewline--dotall)

Adds the `s` modifier to the pattern which will allow you to match a `new line` when using `anything()`

#### `multiline()`

[](#multiline)

Adds the `m` modifier to the pattern which will allow you to search across multiple lines

#### `oneLine() & searchOneLine()`

[](#oneline--searchoneline)

Removes the modifier added by `multiline()` if it was previously called

#### `match( $subject )`

[](#match-subject-)

Simply takes your `$subject` in, compares it against the pattern, and returns whether a it matched or not

#### `replace( $replacement, $subject )`

[](#replace-replacement-subject-)

You can replace matched `segments` by using the `$x` format where `x` is the `(int)` position of the matched `segment`

#### `getPattern()`

[](#getpattern)

Returns the compiled pattern which you can also get by using the `flux` instance in a context where `__toString()` will be called

#### `clear()`

[](#clear)

Clears the created `pattern` along with the `modifiers`, `prefixes`, and `suffixes`

---

### Flux Elsewhere

[](#flux-elsewhere)

There is a straight port of *Flux* for [NodeJS](https://npmjs.org/package/node-flux) *by* [James Brooks](http://james.brooks.so) whom has also collaborated on this project.

### Feedback

[](#feedback)

This is something that started as a weekend experiment but I would love to take it further so if you have any suggestions, please fire away!

*The best way to get in touch with me is via twitter [@selvinortiz](http://twitter.com/selvinortiz) we'll take if from there* :)

### Contributing

[](#contributing)

1. Check for open issues or open a new issue for a feature request or a bug
2. Fork this repo to start making your changes to the `dev` branch or branch off
3. Write a test which shows that the bug was fixed or that the feature works as expected
4. Send a pull request and bug me until I merge it or tell you *no cigar; )*

### Inspiration &amp; Credits

[](#inspiration--credits)

This project is inspired and largely based on [VerbalExpressions:JS](https://github.com/jehna/VerbalExpressions) by [Jesse Luoto](https://plus.google.com/u/0/101155583332851062944/posts)whom on *July 20, 2013* started a weekend project that generated a lot of interest in the developer community and that project has proven to have a lot of potential.

*Flux* is not a straight port of *VerbalExpressions* but if you're interested in a straight *VerbalExpressions* port for *PHP* you should checkout [VerbalExpressions:PHP](https://github.com/markwilson/VerbalExpressionsPhp) by [Mark Wilson](https://github.com/markwilson)

*VerbalExpressions* has also been ported to `Ruby`, `Java`, `Groovy` as of this update (July 25, 2013).

*For a little background as to why *flux* was created and why you should use it, please refer to* [Issue #7](https://github.com/selvinortiz/flux/issues/7)*for a discussion on that matter.*

### MIT License

[](#mit-license)

*Flux* is released under the [MIT license](http://opensource.org/licenses/MIT) which pretty much means you can do with it as you please and I won't get mad because I'm that nice; )

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.8% 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 ~289 days

Total

4

Last Release

3807d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/93d52d70a5bafe64daf0512be1f3473bae56fa5bfb255258e30d6de3dcfcd170?d=identicon)[selvinortiz](/maintainers/selvinortiz)

---

Top Contributors

[![selvinortiz](https://avatars.githubusercontent.com/u/1922523?v=4)](https://github.com/selvinortiz "selvinortiz (24 commits)")[![krolow](https://avatars.githubusercontent.com/u/46822?v=4)](https://github.com/krolow "krolow (2 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![roxburghm](https://avatars.githubusercontent.com/u/8364818?v=4)](https://github.com/roxburghm "roxburghm (1 commits)")

---

Tags

phpregexregularexpressionsfluentflux

### Embed Badge

![Health badge](/badges/selvinortiz-flux/health.svg)

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

###  Alternatives

[spatie/regex

A sane interface for php's built in preg\_\* functions

1.1k17.1M59](/packages/spatie-regex)[gherkins/regexpbuilderphp

PHP port of thebinarysearchtree/regexpbuilderjs

1.4k163.0k1](/packages/gherkins-regexpbuilderphp)

PHPackages © 2026

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