- preg_match: documentation ( source)
<?php
$regex = '/X(*MARK:A)Y|X(*MARK:B)Z/';
preg_match($regex, "XY", $matches);
echo $matches['MARK'], "\n"; // A
preg_match($regex, "XZ", $matches);
echo $matches['MARK'], "\n"; // B
preg_match($regex, "XP", $matches);
echo $matches['MARK'], "\n"; // Should also be B, instead: Notice: Undefined index: MARK