简体   繁体   中英

how to use RegEx.Replace or search string in HTML string using Linq

i want to provide search facility to user. I have html data as string in database. I am using Linq to SQL. But I don't want to search string in the HTML tags. Hence I want to strip the HTML tags from the string I have.

How can I do that?

I know Regex needed is Regex.Replace(inf.EmailSubject, @"<(.|\\n)*?>", string.Empty);

and I do the reading part as below:

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 };

How can I use regex in the contains part?

You can use Regex.IsMatch that does a pattern matching.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM