PHP code example of flexic / regex-builder

1. Go to this page and download the library: Download flexic/regex-builder 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/ */

    

flexic / regex-builder example snippets


$pattern = new \Flexic\RegexBuilder\Pattern();

$pattern->add(
    new \Flexic\RegexBuilder\Expr\Group([
        new \Flexic\RegexBuilder\Expr\LookAround\Ahead(
            new \Flexic\RegexBuilder\Expr\Enclosed(
                new \Flexic\RegexBuilder\Expr\Literal('<picture>'),
            ),
        ),
        new \Flexic\RegexBuilder\Expr\Enclosed(
            new \Flexic\RegexBuilder\Expr\Option([
                new \Flexic\RegexBuilder\Expr\Marker\AnyWord(),
                new \Flexic\RegexBuilder\Expr\Marker\AnyNonWord(),
            ]),
        ),
        new \Flexic\RegexBuilder\Expr\LookAround\Follow(
            new \Flexic\RegexBuilder\Expr\Literal('</picture>'),
        ),
    ]),
);

$pattern->toString(); // returns: '(?=(\<picture\>))(\w|\W)(?<=\<\/picture\>)'