score:-1

you can use the regex function as am using below:

"<div>hello</div><span>world</span>".replace(/<[^>]*>/g, '')

score:1

i think there is no easy answer in your case, but you have several possibilities. regex can be a simple solution if you do not want to get the full tags. a more deeper but more complex would be to use a package like htmlagilitypack to parse your mail.

here is an example of the regex :

var searchword = "strong";
var mail = "<strong>blablabla</strong><p>blabla strong blabla</p>";
var rgx = new regex($"(?!<){searchword}(?!>)"); // will match strong but not <strong> or <strong or strong>
if (rgx.ismatch(mail))
{
    // do what you want
}

score:1

see if you can use free and open source htmlagilitypack through which you can first convert the html text to plain text and then apply the search criteria.

e.g.: var plaintextresult = htmlutilities.converttoplaintext(string html);

if(!string.isnullorwhitespace(searchtext))
{
    bool containsresult = plaintextresult.contains(searchtext);
}

score:1

thanks to @amine and @lollmbaowtfidgafgtfoohwtbs, i figured out how to do this.

first, i created a sql function in my database that strips a given text:


create function [dbo].[ufnstriphtml] (@htmltext nvarchar(max))
returns nvarchar(max) as
begin
    declare @start int
    declare @end int
    declare @length int
    set @start = charindex('<',@htmltext)
    set @end = charindex('>',@htmltext,charindex('<',@htmltext))
    set @length = (@end - @start) + 1
    while @start > 0 and @end > 0 and @length > 0
    begin
        set @htmltext = stuff(@htmltext,@start,@length,'')
        set @start = charindex('<',@htmltext)
        set @end = charindex('>',@htmltext,charindex('<',@htmltext))
        set @length = (@end - @start) + 1
    end
    return ltrim(rtrim(@htmltext))
end
go

then i added a reference to that function in my dbcontext:

        [dbfunction("ufnstriphtml")]
        public static string striphtml(string text)
        {
            throw new exception("not implemented");
        }

and now i can use it in my linq to sql query:


if (!string.isnullorwhitespace(searchtext))
{
    query = query.where(ent => tgdbcontext.striphtml(ent.contents).contains(searchtext));
}

Related Query

More Query from same tag