【问题标题】:how to use RegEx.Replace or search string in HTML string using Linq如何使用 RegEx.Replace 或使用 Linq 在 HTML 字符串中搜索字符串
【发布时间】:2014-05-15 18:57:48
【问题描述】:

我想为用户提供搜索工具。我在数据库中有 html 数据作为字符串。我正在使用 Linq to SQL。但我不想在 HTML 标签中搜索字符串。因此,我想从我拥有的字符串中去除 HTML 标签。

我该怎么做?

我知道需要的正则表达式是Regex.Replace(inf.EmailSubject, @"<(.|\n)*?>", string.Empty);

我的阅读部分如下:

from s in dc.UserLandingPages 
where !s.UserProductDetail.IsDeleted
&& (s.Nickname.Contains(strSearch)
|| s.Headline.Contains(strSearch)
|| s.SubheadLine.Contains(strSearch)
|| s.HTMLData.Contains(strSearch))
select new UserLandingPageResult { _userLandingPage = s };

如何在包含部分使用正则表达式?

【问题讨论】:

    标签: c# html regex string linq


    【解决方案1】:

    您可以使用Regex.IsMatch 进行模式匹配。

    string text = "noname001";
    string pattern = @"[nN]ame"; // either Name or name
    bool status = Regex.IsMatch(text, pattern);
    

    【讨论】:

    • 没关系。但是如何在上面提供的查询中使用它呢?
    • @PratikGaikwad if(status) 或 if(Regex.IsMatch(text, pattern))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 2012-02-14
    • 2013-02-05
    • 2016-06-21
    • 2013-11-09
    • 2022-01-23
    相关资源
    最近更新 更多