[lang-ref] ( string_split_with_regexp ) ( php )
<?php
public function testStringSplitWithRegexp(): void
{
// preg_split($pattern, $s)
$text = 'A, B, C and D';
$pattern = '/(?:,\s*|\s+and\s+)/';
$elems = preg_split($pattern, $text);
$this->assertNotFalse($elems);
$this->assertSame(['A', 'B', 'C', 'D'], $elems);
}