PHP code example of codekandis / regular-expressions

1. Go to this page and download the library: Download codekandis/regular-expressions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codekandis / regular-expressions example snippets


$regularExpression = new RegularExpression( '~[a-z]+[0-9]+~' );

$regularExpression = new RegularExpression( '~[a-z]+[0-9]+~' );
$match             = $regularExpression->match( 'foo01234_bar56789' );
/**
 * $match = [
 *   'foo01234'
 * ]
 */

$regularExpression = new RegularExpression( '~[a-z]+[0-9]+~' );
$matches           = $regularExpression->matchAll( 'foo01234_bar56789' );
/**
 * $matches = [
 *   [
 *     'foo01234',
 *     'bar56789'
 *   ]
 * ]
 */

$regularExpression = new RegularExpression( '~[a-z]+[0-9]+~' );
$replacedSubject   = $regularExpression->replace( 'foo01234_bar56789', 'replacement' );
/**
 * $replacedSubject = 'replacement_replacement'
 */