PHP code example of koca / easyregex

1. Go to this page and download the library: Download koca/easyregex library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

koca / easyregex example snippets


// some tests
use Koca\EasyRegex\EasyRegex;

$regex = new EasyRegex;

$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.", "-");



$regex->find("You have ")
    ->beginCapture("count")
    ->word()
    ->endCapture();

$contributions = $regex->match("You have 258 contributions in the last year");

echo $contributions["count"];

// Output: 258