繁体   English   中英

正则表达式以匹配C#中两个未关闭标签之间的文本

[英]Regex to match text between two unclosed tags in C#

我有以下代码:

<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.

请为我建议一个正确的正则表达式

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

尝试类似

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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