正则表达式,用于匹配 C# 中两个未闭合标记之间的文本

本文关键字:两个 文本 之间 用于 正则表达式 | 更新日期: 2023-09-27 18:36:24

我有以下代码:

<br>
                For Day October 21, 2013, The following locations have been restricted<br>
                <br>
                 No increases in nominations sourced from points west of Southeast for delivery to points east of Southeast, except for Primary Firm No-Notice nominations, will be accepted.<br>

我想匹配所有出现的<br><br>标签之间的文本,就像我需要输出一样:

For Day October 21, 2013, The following locations have been restricted
No increases in nominations sourced from points west of Southeast for delivery to points east of Southeast, except for Primary Firm No-Notice nominations, will be accepted.

请建议我一个适当的正则表达式

正则表达式,用于匹配 C# 中两个未闭合标记之间的文本

您确定需要正则表达式吗?

尝试类似的东西

string output = sourceHtml.Replace("<br>", Environment.NewLine).Trim();

这将删除<br>标签并为您提供预期的结果。

试试这个:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace RegexTester
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = @"<br>
                For Day October 21, 2013, The following locations have been restricted<br>
                <br>
                 No increases in nominations sourced from points west of Southeast for delivery to points east of Southeast, except for Primary Firm No-Notice nominations, will be accepted.<br>";
            var pattern = "<br>''s*";
            var result = Regex.Replace(text, pattern, string.Empty);
            Console.WriteLine(result);
            Console.ReadKey();
        }
    }
}