patrickschur / words2regex
Build your regular expressions based on your texts.
dev-master
2019-01-01 08:02 UTC
Requires
- php: ^7
- ext-mbstring: *
This package is auto-updated.
Last update: 2024-11-17 01:30:23 UTC
README
Build your regular expressions based on your texts. It has never been easier to create regular expressions.
Example 1
<?php require 'vendor/autoload.php'; $regex = new Words2Regex\Words2Regex(); $words = [ 'abc', 'abcde', 'abcdef', 'bbc', 'bbcde', 'bbcdef', 'cbc', 'cbcde', 'cbcdef', ]; foreach ($words as $word) { $regex->add($word); } echo $regex->getRegex();
Output2:
([abc]bc(def?)?)
Example 2
<?php require 'vendor/autoload.php'; $regex = new Words2Regex\Words2Regex(); $words = [ 'foo', 'foobar' ]; foreach ($words as $word) { $regex->add($word); } echo $regex->getRegex();
Output2:
foo(bar)?