$re = '/.*?($|\$[sc]\d)/m';
$str = ' Есть текст и много строк
В тексте встречаются $s1 $s2 $s3 $s4 $c1 $c2 $c4
В каждой строке есть хоть 1 такой текст, могут быть и 2 и 3 в 1 строке, но без дублей.
Найти я смог их так (\\$s\\d)|(\\$c\\d) и удалить могу их всех, но как удалить все кроме них не понял.
Заранее спасибо за ответ! ';
$subst = "$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