Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/folour/regex
Simple and useful abstraction over PHP preg_* functions for PHP 7.1
https://github.com/folour/regex
php71 regex regexp regexp-match regexp-search regular-expressions
Last synced: about 1 month ago
JSON representation
Simple and useful abstraction over PHP preg_* functions for PHP 7.1
- Host: GitHub
- URL: https://github.com/folour/regex
- Owner: folour
- License: gpl-3.0
- Created: 2017-06-08T18:23:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-09T13:40:19.000Z (over 7 years ago)
- Last Synced: 2024-10-13T13:05:52.035Z (2 months ago)
- Topics: php71, regex, regexp, regexp-match, regexp-search, regular-expressions
- Language: PHP
- Size: 17.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Regex
Simple and useful abstraction over PHP preg_* functions for PHP 7.1### Implemented functions
- preg_split
- preg_match
- preg_match_all
- preg_replace
- preg_replace_callback### Installation
```php
composer require folour/regex 'v1.0.0'
```### Usage
```php
replace('/test/i', 'replaced');
//Converts to string and print text 'replaced [string], replaced [value]'
echo $replaced;//fluent replacement
$replaced = $re
->replace('/test/i', 'replaced')
->replace('/replaced/', 'double_replaced');echo $replaced;//'double_replaced [string], double_replaced [value]
//callback replacement
$replaced = $re->replace('/\[([a-z]+)\]/i', function($matches) {
return sprintf('[replaced_%s]', $matches[1]);
});
echo $replaced; //'Test [replaced_string], test [replaced_value]'/*
* find matches
*/
//first match
$m = $re->find('/\[(?P[a-z]+)\]/');
var_dump($m);
// array(
// 'matched' => 'string'
// )//all matches
$m = $re->findAll('/\[(?P[a-z]+)\]/');
var_dump($m);
// array(
// 0 => array(
// 'matched' => 'string'
// ),
// 1 => array(
// 'matched' => 'value'
// )
// )/*
* Split string
*/
$parts = $re->split('/\,\s?/');
var_dump($parts);
// array(
// 0 => 'Test [string]',
// 1 => 'test [value]'
// )
```