<?php

// test Regex class methods
// this script should be run in command-line mode
include 'Regex.class.php';
if (php_sapi_name() == 'cli') {
    $eol = PHP_EOL;
    $tab = "\t";
} else {
    $eol = "<br/>";
    $tab = str_repeat("&nbsp;", 8);
}
// IsRegex() method example
$re = ['/foo bar/', '#foo bar#imsx', '/foo bar'];
foreach ($re as $item) {
    echo "Regex::IsRegex ( {$item} ) = " . (Regex::IsRegex($item) ? 'true' : 'false') . $eol;
}
echo $eol;
// Matches() example
$matches = [['file.txt', '*.txt'], ['file.txt', 'file.*'], ['dir/file.txt', '*.txt'], ['dir/file.txt', 'dir/*.txt'], ['dir/file.txt', '*/*.txt'], ['dir/file.txt', '*\\file.txt']];
foreach ($matches as $match) {
    echo "Regex::Matches ( {$match[0]}, {$match[1]} ) = " . (Regex::Matches($match[0], $match[1]) ? 'true' : 'false') . $eol;
}
echo $eol;
// DevelopExpression() example
$expressions = ['file[0-9].txt', 'file[a-c][0-2].bin'];
foreach ($expressions as $expression) {
    echo "Regex::DevelopExpression ( {$expression} ) = {$eol}{$tab}";
    $developed_expressions = Regex::DevelopExpression($expression);
    echo rtrim(str_replace("\n", "{$eol}{$tab}", print_r($developed_expressions, true)));
    echo "{$eol}";