|
1 |
| -VerbalExpressions v0.1 |
2 |
| -===================== |
| 1 | +##PHPVerbalExpressions |
| 2 | +- ported from [VerbalExpressions](https://github.com/jehna/VerbalExpressions) |
3 | 3 |
|
4 |
| -## JavaScript Regular Expressions made easy |
5 |
| -VerbalExpressions is a JavaScript library that helps to construct difficult regular expressions. |
| 4 | +VerbalExpressions is a PHP library that helps to construct hard regular expressions. |
6 | 5 |
|
7 |
| -## How to get started |
8 | 6 |
|
9 |
| -Include the library and you're good to go! |
10 |
| -```HTML |
11 |
| -<script src="VerbalExpressions.js"></script> |
12 |
| -``` |
| 7 | +```php |
13 | 8 |
|
14 |
| -## Examples |
| 9 | +// some tests |
15 | 10 |
|
16 |
| -Here's a couple of simple examples to give an idea of how VerbalExpressions works: |
| 11 | +$regex = new VerEx; |
17 | 12 |
|
18 |
| -### Testing if we have a valid URL |
| 13 | +$regex ->startOfLine() |
| 14 | + ->then( "http" ) |
| 15 | + ->maybe( "s" ) |
| 16 | + ->then( "://" ) |
| 17 | + ->maybe( "www." ) |
| 18 | + ->anythingBut( " " ) |
| 19 | + ->endOfLine(); |
19 | 20 |
|
20 |
| -```javascript |
21 |
| -// Create an example of how to test for correctly formed URLs |
22 |
| -var tester = VerEx() |
23 |
| - .startOfLine() |
24 |
| - .then( "http" ) |
25 |
| - .maybe( "s" ) |
26 |
| - .then( "://" ) |
27 |
| - .maybe( "www." ) |
28 |
| - .anythingBut( " " ) |
29 |
| - .endOfLine(); |
30 | 21 |
|
31 |
| -// Create an example URL |
32 |
| -var testMe = "https://www.google.com"; |
| 22 | +if($regex->test("http://github.com")) |
| 23 | + echo "valid url"; |
| 24 | +else |
| 25 | + echo "invalid url"; |
33 | 26 |
|
34 |
| -// Use RegExp object's native test() function |
35 |
| -if( tester.test( testMe ) ) alert( "We have a correct URL "); // This output will fire |
36 |
| -else alert( "The URL is incorrect" ); |
37 | 27 |
|
38 |
| -console.log( tester ); // Ouputs the actual expression used: /^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$/ |
39 |
| -``` |
| 28 | +echo "<pre>". $regex->getRegex() ."</pre>"; |
40 | 29 |
|
41 |
| -### Replacing strings |
42 | 30 |
|
43 |
| -```javascript |
44 |
| -// Create a test string |
45 |
| -var replaceMe = "Replace bird with a duck"; |
46 |
| - |
47 |
| -// Create an expression that seeks for word "bird" |
48 |
| -var expression = VerEx().find( "bird" ); |
49 |
| - |
50 |
| -// Execute the expression like a normal RegExp object |
51 |
| -var result = replaceMe.replace( expression, "duck" ); |
52 |
| - |
53 |
| -alert( result ); // Outputs "Replace duck with a duck" |
54 |
| -``` |
55 |
| - |
56 |
| -### Shorthand for string replace: |
57 |
| - |
58 |
| -```javascript |
59 |
| -var result = VerEx().find( "red" ).replace( "We have a red house", "blue" ); |
60 |
| -alert( result ); // Outputs "We have a blue house" |
61 |
| -``` |
62 |
| - |
63 |
| -## API documentation |
64 |
| - |
65 |
| -You can find the API documentation at the [wiki pages](https://github.com/jehna/VerbalExpressions/wiki). |
66 |
| - |
67 |
| -## A little word for a big help |
68 |
| -I'd like to promote a special thank-you to [Ben Nadel][ben-nadel] for his [great article about extending native JS objects][extending] |
69 |
| - |
70 |
| -## Contributions |
71 |
| -Clone the repo and fork: |
72 |
| -`git clone https://github.com/jehna/VerbalExpressions.git`. |
73 |
| - |
74 |
| -Pull requests are warmly welcome! |
75 |
| - |
76 |
| -[ben-nadel]:http://www.bennadel.com/ |
77 |
| -[extending]:http://www.bennadel.com/blog/2292-Extending-JavaScript-Arrays-While-Keeping-Native-Bracket-Notation-Functionality.htm |
| 31 | +echo $regex ->clean(array("modifiers"=> "m","replaceLimit"=>4)) |
| 32 | + ->find(' ') |
| 33 | + ->replace("This is a small test http://somesite.com and some more text.", "-"); |
0 commit comments