{"id":13494101,"url":"https://github.com/VerbalExpressions/PHPVerbalExpressions","last_synced_at":"2025-03-28T13:32:07.756Z","repository":{"id":9651824,"uuid":"11588127","full_name":"VerbalExpressions/PHPVerbalExpressions","owner":"VerbalExpressions","description":"PHP Regular expressions made easy","archived":false,"fork":false,"pushed_at":"2020-06-13T05:13:01.000Z","size":83,"stargazers_count":2413,"open_issues_count":2,"forks_count":144,"subscribers_count":123,"default_branch":"master","last_synced_at":"2025-03-27T20:07:43.963Z","etag":null,"topics":["regular-expression","verbalexpressions"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VerbalExpressions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-22T17:55:17.000Z","updated_at":"2025-03-25T14:10:30.000Z","dependencies_parsed_at":"2022-07-13T16:48:00.498Z","dependency_job_id":null,"html_url":"https://github.com/VerbalExpressions/PHPVerbalExpressions","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerbalExpressions%2FPHPVerbalExpressions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerbalExpressions%2FPHPVerbalExpressions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerbalExpressions%2FPHPVerbalExpressions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerbalExpressions%2FPHPVerbalExpressions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VerbalExpressions","download_url":"https://codeload.github.com/VerbalExpressions/PHPVerbalExpressions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246037477,"owners_count":20713421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["regular-expression","verbalexpressions"],"created_at":"2024-07-31T19:01:21.869Z","updated_at":"2025-03-28T13:32:07.722Z","avatar_url":"https://github.com/VerbalExpressions.png","language":"PHP","funding_links":[],"categories":["PHP","目录","类库"],"sub_categories":["字符串 Strings","文本处理"],"readme":"[![Build Status](https://travis-ci.org/VerbalExpressions/PHPVerbalExpressions.svg)](https://travis-ci.org/VerbalExpressions/PHPVerbalExpressions)\n\n## PHPVerbalExpressions\n- ported from [VerbalExpressions](https://github.com/VerbalExpressions/JSVerbalExpressions)\n\nVerbalExpressions is a PHP library that helps to construct hard regular expressions.  \n\n## Installation\nThe project supports Composer so you have to install [Composer](http://getcomposer.org/doc/00-intro.md#installation-nix) first, before project setup.\n\n```sh\n$ composer require  verbalexpressions/php-verbal-expressions:dev-master\n```\n\n## Examples\n\n```php\n\u003c?php\n// some tests\nrequire './vendor/autoload.php';\nuse VerbalExpressions\\PHPVerbalExpressions\\VerbalExpressions;\n\n$regex = new VerbalExpressions();\n\n$regex-\u003estartOfLine()\n      -\u003ethen(\"http\")\n      -\u003emaybe(\"s\")\n      -\u003ethen(\"://\")\n      -\u003emaybe(\"www.\")\n      -\u003eanythingBut(\" \")\n      -\u003eendOfLine();\n\n\nif ($regex-\u003etest(\"http://github.com\")) {\n    echo \"valid url\". '\u003cbr\u003e';\n} else {\n    echo \"invalid url\". '\u003cbr\u003e';\n}\n\nif (preg_match($regex, 'http://github.com')) {\n    echo 'valid url';\n} else {\n    echo 'invalid url';\n}\n\n\necho \"\u003cpre\u003e\". $regex-\u003egetRegex() .\"\u003c/pre\u003e\";\n\necho $regex-\u003eclean(array(\"modifiers\" =\u003e \"m\", \"replaceLimit\" =\u003e 4))\n           -\u003efind(' ')\n           -\u003ereplace(\"This is a small test http://somesite.com and some more text.\", \"-\");\n\n```\n\nMore examples are available in the following files:\n\n- [Example.php](Example.php)\n- [VerbalExpressionsTest.php](tests/VerbalExpressionsTest.php)\n\n### Business readable language  expression definition\n```PHP\n$definition = 'start, then \"http\", maybe \"s\", then \"://\", maybe \"www.\", anything but \" \", end';\n$regex = new VerbalExpressionsScenario($definition);\n```\n\n## Methods list\n\nName|Description|Usage\n:---|:---|:---\nadd| add values to the expression| add('abc')\nstartOfLine| mark expression with ^| startOfLine(false)\nendOfLine| mark the expression with $|endOfLine()\nthen|add a string to the expression| add('foo')\nfind| alias for then| find('foo')\nmaybe| define a string that might appear once or not| maybe('.com')\nanything| accept any string| anything()\nanythingBut| accept any string but the specified char| anythingBut(',')\nsomething| accept any non-empty string| something()\nsomethingBut| anything non-empty except for these chars| somethingBut('a')\nreplace| shorthand for preg_replace()| replace($source, $val)\nlineBreak| match \\r \\n|lineBreak()\nbr|shorthand for lineBreak| br()\ntab|match tabs \\t |tab()\nword|match \\w+|word()\nanyOf| any of the listed chars| anyOf('abc')\nany| shorthand for anyOf| any('abc')\nrange| adds a range to the expression|range(a,z,0,9)\nwithAnyCase| match case default case sensitive|withAnyCase()\nstopAtFirst|toggles the g modifiers|stopAtFirst()\naddModifier| add a modifier|addModifier('g')\nremoveModifier| remove a mofier|removeModifier('g')\nsearchOneLine| Toggles m modifier|searchOneLine()\nmultiple|adds the multiple modifier| multiple('*')\n_or|wraps the expression in an `or` with the provided value|_or('bar')\nlimit|adds char limit|limit(1,3)\ntest| performs a preg_match| test('valid@email.com')\n\nFor all the above method (except `test`) you could use the `VerbalExpressionsScenario`.\n\n## Other Implementations\nYou can see an up to date list of all ports on [VerbalExpressions.github.io](http://VerbalExpressions.github.io).\n- [Javascript](https://github.com/jehna/VerbalExpressions)\n- [Ruby](https://github.com/VerbalExpressions/RubyVerbalExpressions)\n- [C#](https://github.com/VerbalExpressions/CSharpVerbalExpressions)\n- [Python](https://github.com/VerbalExpressions/PythonVerbalExpressions)\n- [Java](https://github.com/VerbalExpressions/JavaVerbalExpressions)\n- [C++](https://github.com/VerbalExpressions/CppVerbalExpressions)\n\n## Building the project and running the tests\nThe project supports Composer so you have to install [Composer](https://getcomposer.org/doc/00-intro.md#installation-nix) first before project setup.\n\n    curl -sS https://getcomposer.org/installer | php\n    php composer.phar install --dev\n    ln -s vendor/phpunit/phpunit/phpunit.php phpunit\n    ./phpunit\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVerbalExpressions%2FPHPVerbalExpressions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVerbalExpressions%2FPHPVerbalExpressions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVerbalExpressions%2FPHPVerbalExpressions/lists"}