Regex r = new Regex("(?NIL)"); Match m = r.Match("NIL abc 123 NIL abc"); string s = m.Result("${name}"); 这里的s会得到"NIL"。现在我想通过修改正则表达式使得返回的s为空字符串"", 即只要碰到"NIL",就在此处匹配一个空字符串。 请问这里的正则表达式(?NIL)该怎么修改。
string s = "NIL abc 123 NIL abc";
s = s.Replace("NIL","");
or
s = Regex.Replace(s,@"NIL","");
or do you mean ??
Regex r = new Regex(@"(?<name>)NIL");
Match m = r.Match("NIL abc 123 NIL abc");
if (m.Success)
{
string s = m.Result("${name}");
Console.WriteLine(s);
}