$re = '/(?:\/us)?\/[a-z]{2}[_-][a-z]{2}(?:\/?$|(?=\/))|\/[a-z]{2}(?:\/?$|(?=\/))^([a-z]{2}\/retail)/m';
$str = '/us/en_us/retail/en
/us/en_us/retail
/gb/en_gb/retail/en-uk/
/us/en_us/e/retail/Ctral/Apps/jcr:content/par/expandableciner_57473905/image/file.img.png/1496964235.png
/gb/retail/cowabunga
/gb/en_gb/retail/en-uk
/gb/en_gb/retail/en-uk/blah';
$subst = "";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php