menthol / sql-like-to-regex
Simple package to convert (my)sql LIKE syntax to regex (preg)
v1.0.0-beta3
2018-04-15 07:45 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: ^5.0|^6.0|^7.0
This package is auto-updated.
Last update: 2024-11-13 18:38:19 UTC
README
Simple package to convert (my)sql LIKE syntax to regex (preg)
Install
composer require menthol/sql-like-to-regex
Usage
use Menthol\SqlLikeToRegex\SqlLikeToRegex; print (new SqlLikeToRegex) ->setPattern('foo%') ->toRegex(); // => /^foo.*$/i var_dump((new SqlLikeToRegex) ->setPattern('foo%') ->test('FooBar') ); // => bool(true) var_dump((new SqlLikeToRegex) ->setPattern('foo%') ->test('Baz') ); // => bool(false) print (new SqlLikeToRegex) ->setPattern('B_o#(F%o##Moo#%') ->setEscape('#') ->setCaseSensitive() ->toRegex(); // => /^B.o\(F.*o#Moo%$/ print (new SqlLikeToRegex) ->setPattern('_b_a_r_') ->setDelimiter('#') ->toRegex(); // => #^.b.a.r.$#i print (new SqlLikeToRegex) ->setPattern('/.*[baz]{5}^/') ->setDelimiter('<') ->toRegex(); // => <^/\.\*\[baz\]\{5\}\^/$>i
License
This project is open-sourced software licensed under the MIT license