By default this works properly with UTF8 strings.
Do not forget to use preg_quote() first on strings that could potentially contain
unescaped characters.
Note that you still need to add the u modifier (for UTF8) to your pattern yourself.
Example: /some(.*)pattern/u
/** * UtilityTest::testPregMatchWithPatternEscape() * * @covers ::pregMatch * @return void */ public function testPregMatchWithPatternEscape() { $string = 'http://www.example.com/s?q=php.net+docs'; $res = preg_quote($string); $this->assertSame('http\\://www\\.example\\.com/s\\?q\\=php\\.net\\+docs', $res); $string = 'http://www.example.com/s?q=php.net+docs'; $res = preg_quote($string, '/'); $this->assertSame('http\\:\\/\\/www\\.example\\.com\\/s\\?q\\=php\\.net\\+docs', $res); $res = '/a\\s*' . $res . '\\s*z/i'; $string = 'a ' . $string . ' z'; $matches = Utility::pregMatch($res, $string); $expected = [$string]; $this->assertSame($expected, $matches); }