forked from VerbalExpressions/PHPVerbalExpressions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.php
66 lines (44 loc) · 1.2 KB
/
Example.php
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Verbal Expressions v0.1 (https://github.com/jehna/VerbalExpressions) ported in PHP
* @author Mihai Ionut Vilcu ([email protected])
* 22.July.2013
*/
$loader = require __DIR__ . '/vendor/autoload.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.", "-");
echo "<hr>";
// limit
echo $regex ->clean(array("modifiers" => "m"))
->startOfLine()
->anyOf("abc")
->anythingBut(" ")
->limit(1)
->withAnyCase()
->replace("Abracadabra is a nice word", "Ba");
echo "<br>";
echo $regex ->clean(array("modifiers" => "gm"))
->add("\b")
->word()
->limit(2, 3)
->add("\b")
->replace("test abc ab abcd", "*");