Skip to content

Simple package to convert (my)sql LIKE syntax to regex (preg)

License

Notifications You must be signed in to change notification settings

menthol/sqlLikeToRegex

Repository files navigation

Sql Like To Regex

Simple package to convert (my)sql LIKE syntax to regex (preg)

Build Status

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

About

Simple package to convert (my)sql LIKE syntax to regex (preg)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published