Skip to content

Commit 00048b9

Browse files
committed
add regexp function
1 parent 3774f2c commit 00048b9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/FunctionRegistrar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class FunctionRegistrar
1010
Functions\Curdate::class,
1111
Functions\DateFormat::class,
1212
Functions\Substring::class,
13+
Functions\Regexp::class,
1314
];
1415

1516
/**

src/Functions/Regexp.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Appel\SqliteFunctions\Functions;
4+
5+
use Closure;
6+
7+
class Regexp extends AbstractFunction
8+
{
9+
/**
10+
* Thanks to [email protected]
11+
* @see https://www.php.net/manual/en/function.sqlite-create-function.php#120247
12+
* @return \Closure
13+
*/
14+
public function mysql(): Closure
15+
{
16+
return function($pattern, $subject) {
17+
return preg_match('/' . addcslashes($pattern, '/') . '/', $subject);
18+
};
19+
}
20+
}

0 commit comments

Comments
 (0)