PHP code example of chriskonnertz / regex
1. Go to this page and download the library: Download chriskonnertz/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/ */
chriskonnertz / regex example snippets
$regEx = new ChrisKonnertz\RegEx\RegEx();
$regEx->addAnd('http')
->addOption('s')
->addAnd('://')
->addOption('www.')
->addWordChars()
->addAnd('.')
->addWordChars();
echo $regEx;
$regEx->addAnyChar();
$regEx->addAnyChars();
$regEx->addMaybeAnyChars();
$regEx->addDigit();
$regEx->addDigits();
$regEx->addMaybeDigits();
$regEx->addNonDigit();
$regEx->addNonDigits();
$regEx->addMaybeNonDigits();
$regEx->addLetter();
$regEx->addLetters();
$regEx->addMaybeLetters();
$regEx->addWordChar();
$regEx->addWordChars();
$regEx->addMaybeWordChars();
$regEx->addNonWordChar();
$regEx->addNonWordChars();
$regEx->addMaybeNonWordChars();
$regEx->addWhiteSpaceChar();
$regEx->addWhiteSpaceChars();
$regEx->addMaybeWhiteSpaceChars();
$regEx->addTabChar();
$regEx->addTabChars();
$regEx->addMaybeTabChars();
$regEx->addLineBreak();
$regEx->addLineBreak(PHP_EOL);
$regEx->addLineBreaks();
$regEx->addLineBreaks(PHP_EOL);
$regEx->addMaybeLineBreaks();
$regEx->addMaybeLineBreaks(PHP_EOL);
$regEx->addLineBeginning();
$regEx->addLineEnd();
$regEx->addRange('a-z', '123', '\-');
$regEx->addInvertedRange('a-z', '123', '\-');
$regEx->addAnd('ht')->addAnd('tp');
$regEx->addOr('http', 'https');
$regEx->addAnd('http')->addAnd('s');
$regEx->addRepetition(0, 1, "ab"); // Produces "ab?" and matches "ab" and empty string
$regEx->addRepetition(1, 1, "ab"); // Produces "ab" and matches "ab"
$regEx->addRepetition(1, 2, "ab"); // Produces "ab{1,2}" and matches "ab" and "abab".
$regEx->addRepetition(0, RepetitionEx::INFINITE, "ab"); // Produces "ab*" and matches 0..n "ab"
$regEx->addRepetition(1, RepetitionEx::INFINITE, "ab"); // Produces "ab+" and matches 1..n "ab"
$regEx->addRepetition(2, RepetitionEx::INFINITE, "ab"); // Produces "ab{2,}" and matches 2..n "ab"
$regEx->addCapturingGroup('test');
$regEx->addComment('This is a comment');
$quoted = $regEx->quote('Hello.')
$regEx->setModifier(RegEx::MULTI_LINE_MODIFIER_SHORTCUT, true);
$regEx->setInsensitiveModifier();
$regEx->setInsensitiveModifier(true);
$regEx->setInsensitiveModifier(false);
$modifiers = $regEx->getActiveModifiers();
$active = $regEx->isModifierActive(RegEx::MULTI_LINE_MODIFIER_SHORTCUT);
$matches = $regEx->test('https//www.example.com/');
$modified = $regEx->replace('like', 'We hate to hate code');
$regEx->traverse(function($expression, int $level, bool $hasChildren)
{
var_dump($expression, $level, $hasChildren);
});
$regEx->clear();
$flatSize = $regEx->getSize();
$deepSize = $regEx->getSize(true);
$expressions = $regEx->getExpressions();
$start = $regEx->getStart()
$regEx->setStart('/')
$end = $regEx->getEnd()
$regEx->setEnd('/')
$visualisation = $regEx->getStructure(false);
echo $visualisation;
$stringified = $regEx->toString();
$regEx = new ChrisKonnertz\RegEx\RegEx();
$regEx->addRaw(new RangeEx('a-zA-Z'), '+');
echo $regEx;
$regEx = new ChrisKonnertz\RegEx\RegEx();
$regEx->addAnd('First test);
echo $regEx;
$rexEx->clear()->addAnd('Second test');
echo $regEx;