thibaud-dauce/compliant-regexps

An easy way to correct user input based on a regular expression

1.6.0 2016-08-09 10:49 UTC

README

Build Status

The main goal of this library is to provide an easy way to correct user input based on regular expressions.

Installation

composer require thibaud-dauce/compliant-regexps

Usage

The tests folder provides good usage examples.

Basic usage

<?php

$conciliator = new WhiteSpace;
$possibilities = $conciliator->conciliate('/^Flat J114$/', 'Flat J 114');

// $possibilities = ['FlatJ 114', 'Flat J114']
<?php

$conciliator = new StartWith;
$possibilities = $conciliator->conciliate('/^Flat J114$/', 'J114');

// $possibilities = ['Flat J114']

Only valid results

<?php

$conciliator = new ValidOnly(new WhiteSpace);
$possibilities = $conciliator->conciliate('/^Flat J114$/', 'Flat J 114');

// $possibilities = ['Flat J114']

Multiple conciliators

<?php

$conciliator = new Aggregator([new StartWith, new WhiteSpace]);
$possibilities = $conciliator->conciliate('/^Flat J114$/', 'J 114');

// $possibilities = ['J 114', 'Flat J 114', 'J114', 'FlatJ 114', 'Flat J114']

Or with only valid results:

<?php

$conciliator = new ValidOnly(new Aggregator([new StartWith, new WhiteSpace]));
$possibilities = $conciliator->conciliate('/^Flat J114$/', 'J 114');

// $possibilities = ['Flat J114']