{"id":28763633,"url":"https://github.com/selvinortiz/flux","last_synced_at":"2025-06-17T09:10:02.298Z","repository":{"id":9641055,"uuid":"11573911","full_name":"selvinortiz/flux","owner":"selvinortiz","description":"Fluent regular expressions in PHP","archived":false,"fork":false,"pushed_at":"2020-07-30T03:40:09.000Z","size":38,"stargazers_count":339,"open_issues_count":1,"forks_count":19,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-27T08:54:17.303Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/selvinortiz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-22T05:55:13.000Z","updated_at":"2025-01-27T08:56:09.000Z","dependencies_parsed_at":"2022-09-04T10:13:02.005Z","dependency_job_id":null,"html_url":"https://github.com/selvinortiz/flux","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/selvinortiz/flux","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selvinortiz%2Fflux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selvinortiz%2Fflux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selvinortiz%2Fflux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selvinortiz%2Fflux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/selvinortiz","download_url":"https://codeload.github.com/selvinortiz/flux/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selvinortiz%2Fflux/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260326793,"owners_count":22992388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-17T09:10:00.595Z","updated_at":"2025-06-17T09:10:02.285Z","avatar_url":"https://github.com/selvinortiz.png","language":"PHP","funding_links":[],"categories":["杂项","杂项 Miscellaneous","Miscellaneous"],"sub_categories":[],"readme":"## FLUX (Fluent Regex) 0.5.2\n[![Build Status](https://travis-ci.org/selvinortiz/flux.png)](https://travis-ci.org/selvinortiz/flux)\n[![Total Downloads](https://poser.pugx.org/selvinortiz/flux/d/total.png)](https://packagist.org/packages/selvinortiz/flux)\n[![Latest Stable Version](https://poser.pugx.org/selvinortiz/flux/v/stable.png)](https://packagist.org/packages/selvinortiz/flux)\n\n*by* [Selvin Ortiz](http://twitter.com/selvinortiz)\n\n### Description\nFluent Regular Expressions _in_ PHP inspired by and largely based on\n[VerbalExpressions:JS](https://github.com/jehna/VerbalExpressions) by\n[Jesse Luoto](https://plus.google.com/u/0/101155583332851062944/posts)\n\n*@see inspiration \u0026 credits below for more info.*\n\n### Requirements\n- PHP 5.3\n- Composer\n\n### Install\n`Flux` is available as a [package](https://packagist.org/packages/selvinortiz/flux) via [composer](http://getcomposer.org)\n\n* require: `\"selvinortiz/flux\": \"dev-master\"`\n* autoload: `require_once 'path/to/vendor/autoload.php'`\n* namespace: `use SelvinOrtiz\\Utils\\Flux\\Flux;`\n* instantiate: `$flux = Flux::getInstance();`\n\n_You can additionally clone/download this repo and do whatever you want: )_\n\n----\n\n### @Example\nThis simple example illustrates the way you would use `flux` and it's fluent interface to build complex patterns.\n\n```php\nrequire_once realpath(__DIR__.'/../vendor/autoload.php');\n\nuse SelvinOrtiz\\Utils\\Flux\\Flux;\nuse SelvinOrtiz\\Utils\\Flux\\Helper;\n\n// The subject string (URL)\n$str\t= 'http://www.selvinortiz.com';\n\n// Building the pattern (Fluently)\n$flux\t= Flux::getInstance()\n\t\t-\u003estartOfLine()\n\t\t-\u003efind('http')\n\t\t-\u003emaybe('s')\n\t\t-\u003ethen('://')\n\t\t-\u003emaybe('www.')\n\t\t-\u003eanythingBut('.')\n\t\t-\u003eeither('.co', '.com')\n\t\t-\u003eignoreCase()\n\t\t-\u003eendOfLine();\n\n// Output the Flux instance\nHelper::dump( $flux );\n\n// Output the fluently built pattern (@see /src/SelvinOrtiz/Utils/Flux/Helper)\nHelper::msg( $flux ); // /^(http)(s)?(\\:\\/\\/)(www\\.)?([^\\.]*)(.co|.com)$/i\n\n// Inspect the results\nHelper::msg( $str );\nHelper::msg( $flux-\u003ematch( $str ) ? 'matched' : 'unmatched' );\nHelper::msg( $flux-\u003ereplace( 'https://$5$6', $str ) );\n```\n_For other examples, please see the `/etc` directory._\n\n----\n\n### @Changelog\n\n----\n#### 0.5.2\n- Adds `length()` method which adds or replaces the modifier used in the previous call\n- Adds `getLastSegmentKey()`\n- Adds the (empty) `Factory` class for optimized, often used patterns\n- Fixes indentation and EOF on `phpunit.xml`\n- Fixes comment typos on `README` and example files [Pull Request #10](https://github.com/selvinortiz/flux/pull/10)\n\n----\n#### 0.5.1\n- Adds `getSegments()` which was not included in `0.5.0` [Issue #5](https://github.com/selvinortiz/flux/issues/5)\n- Adds `removeSegment()` which can be used in unit tests as well\n- Adds `lineBreak()` and `br()` which matches a new line (DOS/Unix)\n- Adds `clear()` which allows you to clear out the pattern and start from scratch\n- Adds `getPattern()` which compiles the expression and returns it\n- Adds `deprecation candidates as @todos\n- Fixes mixed logic between `add()` and `raw()`\n- Fixes implementation on the `orTry()` method\n- Moves example in readme above `changelog`\n- Improves unit tests\n\n----\n\n#### 0.5.0 (Beta)\n- Adds `getSegments()` to improve testability [Issue #5](https://github.com/selvinortiz/flux/issues/5)\n- Adds composer package [selvinortiz/flux](https://packagist.org/packages/selvinortiz/flux)\n- Adds `dev` branch\n- Adds contributing notes\n- Adds install notes\n\n----\n\n#### 0.4.5\n- Fixes internal namespace conflict\n- Changes namespace from `Sortiz\\Tools` to `SelvinOrtiz\\Utils\\Flux`\n- Adds composer support [Issue #3](https://github.com/selvinortiz/flux/issues/3)\n- Adds the `addSeed()` and `removeSeed()` methods [Issue #4](https://github.com/selvinortiz/flux/issues/4)\n- Adds the `getInstance()` static method\n- Adds `FluxUrlExample.php`, `FluxDateExample.php`, and `FluxPhoneExample.php`\n- Adds `getSeed()` to get the seed without forcing `__toString` on the object\n- Adds `getSegment()` to extract a segment (capturing group) from the pattern\n- Implements unit tests (60% coverage) [Issue #3](https://github.com/selvinortiz/flux/issues/3)\n- Implements Full `PSR-2` Compliance (Tabs over Spaces)\n- Enables the `seed` on `match()` and `replace()` [Issue #4](https://github.com/selvinortiz/flux/issues/4)\n- Removes `example.php` and defines them elsewhere\n- Moves examples into `/etc` and defines one example per file\n- Other small fixes and additions\n\n----\n#### 0.4.0\n- Adds `Flux` to the `Sortiz\\Tools` namespace\n- Implements `PSR-2` Compliance (Tabs over Spaces)\n- Updates version number on `Flux` and this readme file\n- Updates the class instantiation with fully qualified class name on `example.php`\n- Adds references to other repos that have ported `flux`\n- Addresses concerns outlined in [Issue #3](https://github.com/selvinortiz/flux/issues/3)\n\n----\n#### 0.3.0\n- Improves documentation with `phone/date` examples\n- Adds the `letters()` method\n- Renames the `numbers()` method to `digits()`\n- Adds support for quantifiers for `digits()`\n- Adds `ignoreCase()` and promotes it above `inAnyCase()`\n- Improves the documented API\n\n_Thought hard about changing the name to `FluentX` any thoughts?_\n\n----\n#### 0.2.0\n- Adds the `either( $option1, $option2 [, $option3 ...] )` method to handle OR cases\n- Updates the *fluent* example in this readme file\n- Adds the license\n\n----\n#### 0.1.0 (Alpha)\nInitial preview release\n\n----\n\n### @Todo\n- Add source code comments\n- Add support for quantifiers\n- Add language methods for more advanced use cases\n- Add reference to repos that have ported `Flux` (*)\n- Add license notes (*)\n- Add contributing notes (*)\n- Add credits (*)\n\n### FLUX API\nThe **flux** API was designed to give you a _fluent chainable object_ to build patterns with.\n\n#### `startOfLine()`\nAdds a beginning of line `^` modifier\n\n#### `endOfLine()`\nAdds an end of line `$` modifier\n\n#### `find( $val ) \u0026 then( $val )`\nAllows you to augment the pattern with a required `segment` and it escapes regular expression characters\n\n#### `maybe( $val )`\nAllows you to augment the pattern with an optional `segment`\n\n#### `any( $val ) \u0026 anyOf( $val )`\nAllows you to create a set of characters to match\n\n#### `anything()`\nAdds a *wild card* `(.*)` `segment` to the pattern but it does not make `dotAll()` explicit\n\n#### `anythingBut( $val )`\nWill match anything but the characters in `$val` which is opposite of `any()` and `anyOf`\n\n#### `br() \u0026 lineBreak()`\nAllows you to match a new line `(DOS/Unix)`\n\n#### `tab()`\nAdds a `(\\t)` to the pattern which will match a tab\n\n#### `word()`\nAdds `(\\w+)` to the pattern which will match a single word\n\n#### `letters( $min=null, $max=null )`\nOnly matches characters in the alphabet and uses `$min` and `$max` to create a quantifier\n\n#### `digits( $mix=null, $max=null )`\nOnly matches digits and uses `$min` and `$max` to create a quantifier like `word()`\n\n#### `range( $from, $to [, $from, $to ...])`\nAllows you to create a `range` character class like `a-z0-9` by calling `range('a', 'z', 0, 9)`\n\n#### `orTry( $val='' )`\nAllows you to create OR cases `(this)|(else)` and retain the capturing order to use in `replace()`\n\n#### `ignoreCase() \u0026 inAnyCase()`\nAdds the `i` modifier to the pattern which will allow you to match in a case insensitive manner\n\n#### `matchNewLine() \u0026 dotAll()`\nAdds the `s` modifier to the pattern which will allow you to match a `new line` when using `anything()`\n\n#### `multiline()`\nAdds the `m` modifier to the pattern which will allow you to search across multiple lines\n\n#### `oneLine() \u0026 searchOneLine()`\nRemoves the modifier added by `multiline()` if it was previously called\n\n#### `match( $subject )`\nSimply takes your `$subject` in, compares it against the pattern, and returns whether a it matched or not\n\n#### `replace( $replacement, $subject )`\nYou can replace matched `segments` by using the `$x` format where `x` is the `(int)` position of the matched `segment`\n\n#### `getPattern()`\nReturns the compiled pattern which you can also get by using the `flux` instance in a context where `__toString()` will be called\n\n#### `clear()`\nClears the created `pattern` along with the `modifiers`, `prefixes`, and `suffixes`\n\n----\n\n### Flux Elsewhere\nThere 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.\n\n### Feedback\nThis 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!\n\n_The best way to get in touch with me is via twitter [@selvinortiz](http://twitter.com/selvinortiz) we'll take if from there_ :)\n\n### Contributing\n1. Check for open issues or open a new issue for a feature request or a bug\n2. Fork this repo to start making your changes to the `dev` branch or branch off\n3. Write a test which shows that the bug was fixed or that the feature works as expected\n4. Send a pull request and bug me until I merge it or tell you _no cigar; )_\n\n\n### Inspiration \u0026 Credits\nThis project is inspired and largely based on\n[VerbalExpressions:JS](https://github.com/jehna/VerbalExpressions) by\n[Jesse Luoto](https://plus.google.com/u/0/101155583332851062944/posts)\nwhom 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.\n\n*Flux* is not a straight port of *VerbalExpressions* but if you're interested in a straight *VerbalExpressions* port for *PHP* you should checkout\n[VerbalExpressions:PHP](https://github.com/markwilson/VerbalExpressionsPhp) by\n[Mark Wilson](https://github.com/markwilson)\n\n*VerbalExpressions* has also been ported to `Ruby`, `Java`, `Groovy` as of this update (July 25, 2013).\n\n*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)\n*for a discussion on that matter.*\n\n### MIT License\n*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; )\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselvinortiz%2Fflux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fselvinortiz%2Fflux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselvinortiz%2Fflux/lists"}