110,539
社区成员
发帖
与我相关
我的任务
分享
//替换表达式
private string ReplaceQuote(string input)
{
string pattern = @"(?:\\)*(?=['])";
return Regex.Replace(input, pattern, new MatchEvaluator(ReplaceText));
}
// 匹配项
public string ReplaceText(Match m)
{
string str = m.Value;
int n = m.Index;
if (str.Length >= 1)
{
return string.Empty;
}
return @"\";
}
string strInput = @"'qq''''\''\\\\\\\\\\\'dnaaaa";
string re = ReplaceQuote(strInput);
public string ReplaceText(Match m)
{
return @"\";
}
//替换表达式
private string ReplaceQuote(string input)
{
string pattern = @"(?:\\)*')";//这里改成string pattern = @"\\*'";也可以
return Regex.Replace(input, pattern, new MatchEvaluator(ReplaceText));
}
// 匹配项
public string ReplaceText(Match m)
{
return @"\'";
}
Regex.Replace("\\abc",@"\\*","\\");
public string ReplaceText(Match m)
{
string str = m.Value;
int n = m.Index;
if (str.Length >= 1)
{
return string.Empty;
}
return @"\";
}
public string ReplaceText(Match m)
{
return @"\";
}
string test = @"'qq''''\''\\\\\\\\\\\'dnaaaa";
Regex re = new Regex(@"(\\*')");
Console.WriteLine(test);
Console.WriteLine(re.Replace(test, @"\'"));
Console.ReadKey();
([\\]+|(?<=[^\\]))'
如:
this.textBox2.Text=Regex.Replace(this.textBox2.Text,@"([\\]+|(?<=[^\\]))'","\\'");