forked from VerbalExpressions/PHPVerbalExpressions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.php
More file actions
35 lines (28 loc) · 869 Bytes
/
Example.php
File metadata and controls
35 lines (28 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/**
* Verbal Expressions v0.1 (https://github.com/jehna/VerbalExpressions) ported in PHP
* @author Mihai Ionut Vilcu (ionutvmi@gmail.com)
* 22.July.2013
*/
require_once 'VerbalExpressions.php';
$regex = new \VerbalExpressions\PHPVerbalExpressions\VerbalExpressions();
$regex->startOfLine()
->then("http")
->maybe("s")
->then("://")
->maybe("www.")
->anythingBut(" ")
->endOfLine();
if($regex->test("http://github.com"))
echo "valid url". '<br>';
else
echo "invalid url". '<br>';
if (preg_match($regex, 'http://github.com')) {
echo 'valid url';
} else {
echo 'invalud 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.", "-");