PHP code example of cawa0505 / verbal-expressions-php
1. Go to this page and download the library: Download cawa0505/verbal-expressions-php 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/ */
cawa0505 / verbal-expressions-php example snippets
$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.", "-");