PHP code example of thejano / easy-php-regex

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

    

thejano / easy-php-regex example snippets


use TheJano\EasyRegex\EasyRegex;

$regex = (new EasyRegex())
    ->startAnchor()
    ->word()
    ->oneOrMore()
    ->add('@')
    ->word()
    ->oneOrMore()
    ->add('.')
    ->word()
    ->between(2, 5)
    ->endAnchor()
    ->toRegExp();

// Output: /^\w+@\w+\.\w{2,5}$/

$regex = (new EasyRegex())
    ->startAnchor()
    ->hasLetter()
    ->hasDigit()
    ->hasSpecialCharacter()
    ->atLeast(8)
    ->endAnchor()
    ->toRegExp();

// Output: /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}$/

$regex = (new EasyRegex())
    ->protocol()
    ->www()
    ->word()
    ->oneOrMore()
    ->tld()
    ->path()
    ->toRegExp();

// Output: /https?:\/\/(www\.)?\w+\.[a-zA-Z]{2,}(\/\w*)*/