2017 © Pedro Peláez
 

library regexpbuilderphp

PHP port of thebinarysearchtree/regexpbuilderjs

image

gherkins/regexpbuilderphp

PHP port of thebinarysearchtree/regexpbuilderjs

  • Wednesday, February 8, 2017
  • by gherkins
  • Repository
  • 45 Watchers
  • 836 Stars
  • 7,009 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 40 Forks
  • 1 Open issues
  • 9 Versions
  • 7 % Grown

The README.md

 ____            _____            ____        _ _     _           ____  _   _ ____  
|  _ \ ___  __ _| ____|_  ___ __ | __ ) _   _(_) | __| | ___ _ __|  _ \| | | |  _ \ 
| |_) / _ \/ _` |  _| \ \/ / '_ \|  _ \| | | | | |/ _` |/ _ \ '__| |_) | |_| | |_) |
|  _ <  __/ (_| | |___ >  <| |_) | |_) | |_| | | | (_| |  __/ |  |  __/|  _  |  __/ 
|_| \_\___|\__, |_____/_/\_\ .__/|____/ \__,_|_|_|\__,_|\___|_|  |_|   |_| |_|_|    
           |___/           |_|                                                      

human-readable regular expressions for PHP

release release phpunit release release, (*1)

PHP port of regexpbuilderjs, (*2)

RegExpBuilder integrates regular expressions into the programming language, thereby making them easy to read and maintain. Regular Expressions are created by using chained methods and variables such as arrays or strings., (*3)

Installation

composer req gherkins/regexpbuilderphp

Or download the appropriate release and require RegExpBuilder.php and RegExp.php from /src., (*4)

Documentation

https://github.com/gherkins/regexpbuilderphp/wiki, (*5)

Examples

use Gherkins\RegExpBuilderPHP;
$builder = new RegExpBuilder();

Validation

$regExp = $builder
    ->startOfInput()
    ->exactly(4)->digits()
    ->then("_")
    ->exactly(2)->digits()
    ->then("_")
    ->min(3)->max(10)->letters()
    ->then(".")
    ->anyOf(array("png", "jpg", "gif"))
    ->endOfInput()
    ->getRegExp();

//true
$regExp->matches("2020_10_hund.jpg");
$regExp->matches("2030_11_katze.png");
$regExp->matches("4000_99_maus.gif");

//false
$regExp->matches("123_00_nein.gif");
$regExp->matches("4000_0_nein.pdf");
$regExp->matches("201505_nein.jpg");
$regExp = $builder
    ->multiLine()
    ->globalMatch()
    ->min(1)->max(10)->anythingBut(" ")
    ->anyOf(array(".pdf", ".doc"))
    ->getRegExp();

$text = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy SomeFile.pdf eirmod tempor invidunt ut labore et dolore
magna aliquyam erat, sed diam voluptua. At vero eos et accusam
et justo duo dolores et ea rebum. doc_04.pdf Stet clita kasd File.doc.'

$matches = $regExp->findIn($text);

//true
($matches[0] === "SomeFile.pdf");
($matches[1] === "doc_04.pdf");
($matches[2] === "File.doc");

Replace

$regExp = $builder
    ->min(1)
    ->max(10)
    ->digits()
    ->getRegExp();

$text = "98 bottles of beer on the wall";

$text = $regExp->replace(
    $text,
    function ($match) {
        return (int)$match + 1;
    }
);

//true
("99 bottles of beer on the wall" === $text);

Validation with multiple patterns

$a = $builder
    ->startOfInput()
    ->exactly(3)->digits()
    ->anyOf(array(".pdf", ".doc"))
    ->endOfInput();

$b = $builder
    ->getNew()
    ->startOfInput()
    ->exactly(4)->letters()
    ->then(".jpg")
    ->endOfInput();

$regExp = $builder
    ->getNew()
    ->eitherFind($a)
    ->orFind($b)
    ->getRegExp();

//true
$regExp->matches("123.pdf");
$regExp->matches("456.doc");
$regExp->matches("bbbb.jpg");
$regExp->matches("aaaa.jpg");

//false
$regExp->matches("1234.pdf");
$regExp->matches("123.gif");
$regExp->matches("aaaaa.jpg");
$regExp->matches("456.docx");

Take a look at the tests for more examples, (*6)

The Versions

08/02 2017

dev-master

9999999-dev https://github.com/gherkins/regexpbuilderphp/

PHP port of thebinarysearchtree/regexpbuilderjs

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php regex builder

08/02 2017

0.8.0

0.8.0.0 https://github.com/gherkins/regexpbuilderphp/

PHP port of thebinarysearchtree/regexpbuilderjs

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php regex builder

05/02 2017

dev-gherkins-travis

dev-gherkins-travis https://github.com/gherkins/regexpbuilderphp/

PHP port of thebinarysearchtree/regexpbuilderjs

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

php regex builder

24/12 2015

0.7.5

0.7.5.0 https://github.com/gherkins/regexpbuilderphp/

PHP port of thebinarysearchtree/regexpbuilderjs

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

php regex builder

02/12 2015

0.7.4

0.7.4.0 https://github.com/gherkins/regexpbuilderphp/

PHP port of thebinarysearchtree/regexpbuilderjs

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

php regex builder

26/02 2015

0.7.3

0.7.3.0 https://github.com/gherkins/regexpbuilderphp/

PHP port of thebinarysearchtree/regexpbuilderjs

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

php regex builder

20/02 2015

0.7.2

0.7.2.0 https://github.com/gherkins/regexpbuilderphp/

PHP port of thebinarysearchtree/regexpbuilderjs

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

php regex builder

20/02 2015

0.7.1

0.7.1.0 https://github.com/gherkins/regexpbuilderphp/

PHP port of thebinarysearchtree/regexpbuilderjs

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

php regex builder

19/02 2015

0.7.0

0.7.0.0 https://github.com/gherkins/regexpbuilderphp/

PHP port of thebinarysearchtree/regexpbuilderjs

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

php regex builder