C# 要通过包含html标记查找的Regx匹配表达式 var TextToFind=“术语是固定的”; var TexToSearch=“术语是固定的”;

C# 要通过包含html标记查找的Regx匹配表达式 var TextToFind=“术语是固定的”; var TexToSearch=“术语是固定的”;,c#,regex,C#,Regex,现在使用的表达式是(?mi)\b术语是固定的\b 我们如何修改现有的表达式模式以查找带有标记的文本?您可以按如下方式执行此操作 var TextToFind = "The Term is Fixed"; var TexToSearch = "<head>The</head> Term is Fixed"; string str=“术语是固定的”; string textWithoutTags=Regex.Replace(str,

现在使用的表达式是
(?mi)\b术语是固定的\b


我们如何修改现有的表达式模式以查找带有标记的文本?

您可以按如下方式执行此操作

var TextToFind  = "The Term is Fixed";
var TexToSearch = "<head>The</head> Term is Fixed";
string str=“术语是固定的”;
string textWithoutTags=Regex.Replace(str,“]*>”,string.Empty);

您可以按如下方式执行此操作

var TextToFind  = "The Term is Fixed";
var TexToSearch = "<head>The</head> Term is Fixed";
string str=“术语是固定的”;
string textWithoutTags=Regex.Replace(str,“]*>”,string.Empty);

要将所有子字符串与标记或单词之间的空格相匹配,可以动态构造一个类似正则表达式的

string str = "< head > The </ head > Term is Fixed";
string textWithoutTags = Regex.Replace(str, "<[^>]*>", string.Empty);
输出:

var TextToFind  = "The Term is Fixed";
var TexToSearch = "<head>The</head> Term is Fixed\n<head>The</head> Term <span>is</span> Fixed";
var regex = string.Join(@"(?>\s*<[^>]*>\s*|\s+)", TextToFind.Split());
var result = Regex.Matches(TexToSearch, regex).Cast<Match>().Select(x => x.Value);
foreach (var s in result)
    Console.WriteLine(s);
这个术语是固定的
期限是固定的

要将所有子字符串与标记或单词之间的空格相匹配,可以动态构造一个类似正则表达式的

string str = "< head > The </ head > Term is Fixed";
string textWithoutTags = Regex.Replace(str, "<[^>]*>", string.Empty);
输出:

var TextToFind  = "The Term is Fixed";
var TexToSearch = "<head>The</head> Term is Fixed\n<head>The</head> Term <span>is</span> Fixed";
var regex = string.Join(@"(?>\s*<[^>]*>\s*|\s+)", TextToFind.Split());
var result = Regex.Matches(TexToSearch, regex).Cast<Match>().Select(x => x.Value);
foreach (var s in result)
    Console.WriteLine(s);
这个术语是固定的
期限是固定的

请给出几个示例通过修改说明添加示例。请检查。请给出几个示例。通过修改说明添加示例。请检查。Hi@Harish Shisode谢谢,但我们不打算删除/更改原文,有没有办法将其包含在表达式中?Hi@Harish Shisode谢谢,但我们不打算删除/更改原文,有没有办法将其包含在表达式中?