Neos\Eel\Helper\StringHelper::pregMatch PHP Метод

pregMatch() публичный Метод

Example:: String.pregMatch("For more information, see Chapter 3.4.5.1", "/(chapter \d+(\.\d)*)/i") == ['Chapter 3.4.5.1', 'Chapter 3.4.5.1', '.1']
public pregMatch ( string $string, string $pattern ) : array
$string string The input string
$pattern string A PREG pattern
Результат array The matches as array or NULL if not matched
    public function pregMatch($string, $pattern)
    {
        $number = preg_match($pattern, $string, $matches);
        if ($number === false) {
            throw new EvaluationException('Error evaluating regular expression ' . $pattern . ': ' . preg_last_error(), 1372793595);
        }
        if ($number === 0) {
            return null;
        }
        return $matches;
    }

Usage Example

 /**
  * @test
  * @dataProvider pregMatchExamples
  */
 public function pregMatchWorks($string, $pattern, $expected)
 {
     $helper = new StringHelper();
     $result = $helper->pregMatch($string, $pattern);
     $this->assertSame($expected, $result);
 }