cawa0505/verbal-expressions-php

PHP Regular expressions made easy.

v1.0.0 2019-04-06 22:24 UTC

This package is auto-updated.

Last update: 2024-05-07 09:17:48 UTC


README

Verbal Expressions is a PHP library that helps to construct hard regular expressions.

Examples

$regex = new VerbalExpressions;

$regex->startOfLine()
    ->then("http")
    ->maybe("s")
    ->then("://")
    ->maybe("www.")
    ->anythingBut(" ")
    ->endOfLine();

if ($regex->test("https://github.com/")) {
    echo "valid url";
} else {
    echo "invalid url";
}

if (preg_match($regex, 'http://github.com')) {
    echo 'valid url';
} else {
    echo 'invalid url';
}

echo "<pre>". $regex->getRegex() ."</pre>";

echo $regex->clean(array("modifiers" => "m", "replaceLimit" => 4))
    ->find(' ')
    ->replace("This is a small test http://somesite.com and some more text.", "-");

Other Implementations

You can see an up to date list of all ports on VerbalExpressions.github.io.

Building the project and running the tests

All tests are written using PHPUnit. Please ensure that you have it installed and run all tests before contributing.