PHPackages                             menthol/sql-like-to-regex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. menthol/sql-like-to-regex

ActiveLibrary[Database &amp; ORM](/categories/database)

menthol/sql-like-to-regex
=========================

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

v1.0.0-beta3(8y ago)0243MITPHPPHP &gt;=5.4

Since Apr 10Pushed 8y ago1 watchersCompare

[ Source](https://github.com/menthol/sqlLikeToRegex)[ Packagist](https://packagist.org/packages/menthol/sql-like-to-regex)[ RSS](/packages/menthol-sql-like-to-regex/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (4)Used By (0)

Sql Like To Regex
=================

[](#sql-like-to-regex)

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

[![Build Status](https://camo.githubusercontent.com/a9be4234616ebad10c9766880025f38561cb13a4968c0de99a2fc9b77f064bd3/68747470733a2f2f7472617669732d63692e6f72672f6d656e74686f6c2f73716c4c696b65546f52656765782e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/menthol/sqlLikeToRegex)

Install
-------

[](#install)

```
composer require menthol/sql-like-to-regex
```

Usage
-----

[](#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('
