using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @".*?($|\$[sc]\d)";
string substitution = @"$1";
string input = @" Есть текст и много строк
В тексте встречаются $s1 $s2 $s3 $s4 $c1 $c2 $c4
В каждой строке есть хоть 1 такой текст, могут быть и 2 и 3 в 1 строке, но без дублей.
Найти я смог их так (\$s\d)|(\$c\d) и удалить могу их всех, но как удалить все кроме них не понял.
Заранее спасибо за ответ! ";
RegexOptions options = RegexOptions.Multiline;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
}
}
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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx