Description
VerbalExpressions is a PHP library that helps to construct hard regular expressions.
PHPVerbalExpressions alternatives and similar libraries
Based on the "Miscellaneous" category.
Alternatively, view PHPVerbalExpressions alternatives based on common mentions on social networks and blogs.
-
Country List
:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats. -
Hprose-PHP
Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP -
SuperClosure
Serialize closures. Not maintained. Consider using opis/closure. -
dotenv-linter
⚡️Lightning-fast linter for .env files. Written in Rust 🦀 -
Pagerfanta
Pagination library for PHP applications with support for several data providers -
Essence
Extracts information about web pages, like youtube videos, twitter statuses or blog articles. -
sabre/vobject
:date: The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects -
html2text
A PHP component to convert HTML into a plain text format -
RMT
RMT is a handy tool to help releasing new version of your software -
JSONPCallbackValidator
JSONP callback validator. -
Token Bucket
Implementation of the Token Bucket algorithm in PHP. -
Prooph Service Bus
PHP Lightweight Message Bus supporting CQRS. -
Lodash-PHP
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP -
PHP-GPIO
A PHP library to play with the Raspberry PI's GPIO pins -
Embera
A Oembed consumer library, that gives you information about urls. It helps you replace urls to youtube or vimeo for example, with their html embed code. It has advanced features like offline support, responsive embeds and caching support. -
noCAPTCHA
:passport_control: Helper for Google's new noCAPTCHA (reCAPTCHA v2 & v3) -
ClassPreloader
Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files. -
Metrics
Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics (functional) API that doesn't cause vendor lock-in. -
Slimdump
A tool for creating configurable dumps of large MySQL-databases. -
git-profile
Utility that helps you switch git configurations with ease. -
Cake Utility
[READ-ONLY] CakePHP Utility classes such as Inflector, Text, Hash, Security and Xml. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp -
RedisSessionHandler
An alternative Redis session handler for PHP featuring per-session locking and session fixation protection -
html-object
A set of classes to create and manipulate HTML objects abstractions -
Opengraph
A PHP 5.3+ and PHP 7.3 framework for OpenGraph Protocol -
Sslurp
Sslurp is a simple library which aims to make properly dealing with SSL in PHP suck less. -
Procrastinator
Execute time consuming tasks as late as possible in a request -
Alias
FuelPHP Framework - Class and Namespace alias library -
Yell
PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects.
Tired of breaking your main and manually rebasing outdated pull requests?
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of PHPVerbalExpressions or a related project?
README
PHPVerbalExpressions
- ported from VerbalExpressions
VerbalExpressions is a PHP library that helps to construct hard regular expressions.
Installation
The project supports Composer so you have to install Composer first, before project setup.
$ composer require verbalexpressions/php-verbal-expressions:dev-master
Examples
<?php
// some tests
require './vendor/autoload.php';
use VerbalExpressions\PHPVerbalExpressions\VerbalExpressions;
$regex = new VerbalExpressions();
$regex->startOfLine()
->then("http")
->maybe("s")
->then("://")
->maybe("www.")
->anythingBut(" ")
->endOfLine();
if ($regex->test("http://github.com")) {
echo "valid url". '<br>';
} else {
echo "invalid url". '<br>';
}
if (preg_match($regex, 'http://github.com')) {
echo 'valid url';
} else {
echo 'invalid url';
}
echo "<pre>". $regex->getRegex() ."</pre>";
echo $regex->clean(array("modifiers" => "m", "replaceLimit" => 4))
->find(' ')
->replace("This is a small test http://somesite.com and some more text.", "-");
More examples are available in the following files:
- [Example.php](Example.php)
- [VerbalExpressionsTest.php](tests/VerbalExpressionsTest.php)
Business readable language expression definition
$definition = 'start, then "http", maybe "s", then "://", maybe "www.", anything but " ", end';
$regex = new VerbalExpressionsScenario($definition);
Methods list
Name | Description | Usage |
---|---|---|
add | add values to the expression | add('abc') |
startOfLine | mark expression with ^ | startOfLine(false) |
endOfLine | mark the expression with $ | endOfLine() |
then | add a string to the expression | add('foo') |
find | alias for then | find('foo') |
maybe | define a string that might appear once or not | maybe('.com') |
anything | accept any string | anything() |
anythingBut | accept any string but the specified char | anythingBut(',') |
something | accept any non-empty string | something() |
somethingBut | anything non-empty except for these chars | somethingBut('a') |
replace | shorthand for preg_replace() | replace($source, $val) |
lineBreak | match \r \n | lineBreak() |
br | shorthand for lineBreak | br() |
tab | match tabs \t | tab() |
word | match \w+ | word() |
anyOf | any of the listed chars | anyOf('abc') |
any | shorthand for anyOf | any('abc') |
range | adds a range to the expression | range(a,z,0,9) |
withAnyCase | match case default case sensitive | withAnyCase() |
stopAtFirst | toggles the g modifiers | stopAtFirst() |
addModifier | add a modifier | addModifier('g') |
removeModifier | remove a mofier | removeModifier('g') |
searchOneLine | Toggles m modifier | searchOneLine() |
multiple | adds the multiple modifier | multiple('*') |
_or | wraps the expression in an or with the provided value |
_or('bar') |
limit | adds char limit | limit(1,3) |
test | performs a preg_match | test('[email protected]') |
For all the above method (except test
) you could use the VerbalExpressionsScenario
.
Other Implementations
You can see an up to date list of all ports on VerbalExpressions.github.io.
Building the project and running the tests
The project supports Composer so you have to install Composer first before project setup.
curl -sS https://getcomposer.org/installer | php
php composer.phar install --dev
ln -s vendor/phpunit/phpunit/phpunit.php phpunit
./phpunit