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::testPregMatchAll() * * @covers ::pregMatchAll * @return void */ public function testPregMatchAll() { $string = 'D-81245 München'; preg_match_all('/(*UTF8)([\\w+])-([a-z0-9]+)\\s+\\b([\\w\\s]+)\\b/iu', $string, $matches, PREG_SET_ORDER); $expected = [[$string, 'D', '81245', 'München']]; $this->assertSame($expected, $matches); // we dont need the utf8 hack: $matches = Utility::pregMatchAll('/([\\w+])-([a-z0-9]+)\\s+\\b([\\w\\s]+)\\b/iu', $string); $this->assertSame($expected, $matches); }