$re = '/(.+)/m';
$str = 's01e01
s01e02
s01e03
s01e05
s01e06
s01e07
s01e08
s01e10
s01e11
s01e12
s01e14
s01e15
s02e02
s02e03
s02e04
s02e05
s02e07
s03e01
s03e05
s04e01
s04e02
s04e04
s04e05
s04e06
';
$subst = "move \1\\*.* . && rd \1";
$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