c# - 正则表达式不是有效的类型或命名空间 C#

标签 c# regex

我正在尝试将此片段添加到我的代码中:

public string Highlight(string InputTxt)
{
    string Search_Str = txtSearch.Text.ToString();

    // Setup the regular expression and add the Or operator.
    Regex RegExp = new Regex(Search_Str.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase);

    // Highlight keywords by calling the 
    //delegate each time a keyword is found.
    return RegExp.Replace(InputTxt, new MatchEvaluator(ReplaceKeyWords));

    // Set the RegExp to null.
    RegExp = null;
}

但是,由于某种原因,“Regex”没有出现——找不到类型或命名空间。我想我一定是在使用较新版本的 C# - 任何人都可以帮助我用更新的方法来做到这一点吗?我正在使用 System.Text.RegularExpressions.Regex - 也许他们完全摆脱了它?

最佳答案

using System.Text.RegularExpressions;

尝试那个命名空间。

关于c# - 正则表达式不是有效的类型或命名空间 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7431739/

相关文章:

c# - 最小起订量有什么用?

regex - 用于匹配 IP 地址的 Python 正则表达式逻辑

c# 依赖注入(inject)无法将 lambda 转换为预期的委托(delegate)

c# - 如何将解决方案资源管理器中的文件类型从表单更改为类

c# - 如何避免 TCP 套接字在断开连接时抛出 SocketException?

regex - 如何根据真实数据自动创建模式?

javascript - 如何在 nodejs 中用单个正则表达式匹配多个字符串?

regex - mod_rewrite : can a back reference be referenced twice?

python - pandas str.contains 匹配多个字符串并获取匹配的值

c# - ASP.NET MVC "The call is ambiguous"错误 (System.IO.TextWriter.Write)