{"id":36372652,"url":"https://github.com/mcustiel/php-simple-regex","last_synced_at":"2026-01-11T14:02:18.988Z","repository":{"id":34959047,"uuid":"39034465","full_name":"mcustiel/php-simple-regex","owner":"mcustiel","description":"This library allows developers to execute preg_* functions in PHP and use the results as objects, making the use of preg_* functions testeable. PhpSimpleRegex is integrated with PhpVerbalExpressions and Flux, to allow a full Object Oriented Regular Expressions use.","archived":false,"fork":false,"pushed_at":"2017-07-21T08:54:17.000Z","size":54,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-20T17:35:44.553Z","etag":null,"topics":["php","preg","regex","regular-expression"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcustiel.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":"2015-07-13T20:03:20.000Z","updated_at":"2025-01-29T19:31:18.000Z","dependencies_parsed_at":"2022-09-06T00:21:44.332Z","dependency_job_id":null,"html_url":"https://github.com/mcustiel/php-simple-regex","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/mcustiel/php-simple-regex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcustiel%2Fphp-simple-regex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcustiel%2Fphp-simple-regex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcustiel%2Fphp-simple-regex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcustiel%2Fphp-simple-regex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcustiel","download_url":"https://codeload.github.com/mcustiel/php-simple-regex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcustiel%2Fphp-simple-regex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28306985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T11:18:18.743Z","status":"ssl_error","status_checked_at":"2026-01-11T11:07:56.842Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["php","preg","regex","regular-expression"],"created_at":"2026-01-11T14:02:18.791Z","updated_at":"2026-01-11T14:02:18.974Z","avatar_url":"https://github.com/mcustiel.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-simple-regex\n\nWhat is it\n----------\n\nPhpSimpleRegex is an object oriented regular expressions library for PHP.\n\nThis library allows to execute preg_* functions in PHP and use the results as objects, making the use of preg_* functions testeable. PhpSimpleRegex is integrated with [VerbalExpressions\\PHPVerbalExpressions\\VerbalExpressions](https://github.com/VerbalExpressions/PHPVerbalExpressions), [SelvinOrtiz\\Utils\\Flux\\Flux](https://github.com/selvinortiz/flux) and also [MarkWilson\\VerbalExpression](https://github.com/markwilson/VerbalExpressionsPhp) to allow a full Object Oriented approach to Regular Expressions in PHP.\n\n[![Build Status](https://scrutinizer-ci.com/g/mcustiel/php-simple-regex/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mcustiel/php-simple-regex/build-status/master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mcustiel/php-simple-regex/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mcustiel/php-simple-regex/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/mcustiel/php-simple-regex/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/mcustiel/php-simple-regex/?branch=master)\n\nInstallation\n------------\n\n#### Composer:\n\nIf you want to access directly to this repo, adding this to your composer.json should be enough:\n\n```json\n{\n    \"require\": {\n        \"mcustiel/php-simple-regex\": \"*\"\n    }\n}\n```\n\nOr just download the release and include it in your path.\n\nHow to use it?\n--------------\n\nThis library provides a _facade_ class that wraps most of the preg_* functions from PHP. All you need to do is to create an instance of this class and call the methods you need.\n\n```php\nuse Mcustiel\\PhpSimpleRegex\\Executor as RegexExecutor;\n\n$regexFacade = new RegexExecutor();\n```\n\n#### List of methods:\n\n* MatchResult __getAllMatches__(mixed $pattern, string $subject, integer $offset = 0)\n* Match __getOneMatch__(mixed $pattern, string $subject, integer $offset = 0)\n* boolean __match__(mixed $pattern, string $subject, integer $offset = 0)\n* ReplaceResult __replaceAndCount__(mixed $pattern, string $replacement, mixed $subject, integer $limit = -1)\n* mixed __replace__(mixed $pattern, string $replacement, mixed $subject, integer $limit = -1)\n* mixed __replaceCallback__(mixed $pattern, callable $callback, mixed $subject, integer $limit = -1)\n* ReplaceResult __replaceCallbackAndCount__(mixed $pattern, callable $callback, mixed $subject, integer $limit = -1)\n* array __split__(mixed $pattern, string $string, integer $limit = -1, bool $returnOnlyNotEmpty = false, bool $captureOffset = false, bool $captureSubpatterns = false)\n* array __grep__(mixed $pattern, array $input)\n* array __grepNotMatching__(mixed $pattern, array $input)\n\nFor each method, the pattern can be a string, a Flux object, or a PhpVerbalExpression object.\n\nExamples:\n---------\n\n#### getAllMatches:\n\n```php\ntry {\n    $result = $regexFacade-\u003egetAllMatches('/\\d+/', 'ab12cd34ef56');\n    echo 'Number of matches: ' . $result-\u003egetMatchesCount() . PHP_EOL; // Prints 3\n    echo 'First match: ' . $result-\u003egetMatchAt(0)-\u003egetFullMatch() . PHP_EOL; // Prints 12\n    \n    // Iterate over results\n    foreach ($result as $index =\u003e $match) {\n        echo \"Match at index {$index} is \" . $match-\u003egetFullMatch() . PHP_EOL; \n    }\n} catch (\\Exception $e) {\n    echo 'An error occurred executing getAllMatches';\n}\n```\n\n#### getOneMatch:\n\n```php\ntry {\n    $result = $regexFacade-\u003egetOneMatch('/\\d+/', 'ab12cd34ef56');\n    if (!empty($result)) {\n        echo 'Match: ' . $result-\u003egetFullMatch() . PHP_EOL; // Prints 12\n    }\n} catch (\\Exception $e) {\n    echo 'An error occurred executing getOneMatch';\n}\n```\n\n#### match:\n\n```php\ntry {\n    if ($regexFacade-\u003ematch('/\\d+/', 'ab12cd34ef56')) {\n        echo 'String matches pattern.'. PHP_EOL;\n    } else {\n        echo 'String does not match pattern.'. PHP_EOL;\n    }\n} catch (\\Exception $e) {\n    echo 'An error occurred executing match';\n}\n```\n\n#### replaceAndCount:\n\n```php\ntry {\n    // Subject can also be an array.\n    $result = $this-\u003eexecutor-\u003ereplaceAndCount('/\\d+/', 'potato', 'ab12cd34ef56');\n    echo 'Number of replacements: ' . $result-\u003egetReplacements() . PHP_EOL;\n    echo 'Replaced string: ' . $result-\u003egetResult() . PHP_EOL;\n} catch (\\Exception $e) {\n    echo 'An error occurred executing replaceAndCount';\n}\n```\n\n#### replace:\n\n```php\ntry {\n    // Subject can also be a string.\n    $result = $this-\u003eexecutor-\u003ereplaceAndCount('/\\d+/', 'potato', ['ab12cd34ef56', 'ab12cd78ef90']);\n    echo 'Replaced strings: ' . print_r($result-\u003egetResult(), true) . PHP_EOL;\n} catch (\\Exception $e) {\n    echo 'An error occurred executing replace';\n}\n```\n\n#### replaceCallback:\n\n```php\ntry {\n    // Subject can also be an array.\n    $result = $this-\u003eexecutor-\u003ereplaceCallback('/\\d+/', function () { return 'potato'; }, 'ab12cd34ef56');\n    echo 'Replaced string: ' . $result-\u003egetResult() . PHP_EOL;\n} catch (\\Exception $e) {\n    echo 'An error occurred executing replaceCallback';\n}\n```\n\n#### replaceCallbackAndCount:\n\n```php\ntry {\n    // Subject can also be an array.\n    $result = $this-\u003eexecutor-\u003ereplaceCallback('/\\d+/', function () { return 'potato'; }, 'ab12cd34ef56');\n    echo 'Number of replacements: ' . $result-\u003egetReplacements() . PHP_EOL;\n    echo 'Replaced string: ' . $result-\u003egetResult() . PHP_EOL;\n} catch (\\Exception $e) {\n    echo 'An error occurred executing replaceCallbackAndCount';\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcustiel%2Fphp-simple-regex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcustiel%2Fphp-simple-regex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcustiel%2Fphp-simple-regex/lists"}