从字符串末尾删除<br>标签的最佳方法是什么?

Ele*_*hoy 6 .net asp.net string xhtml

我正在研究的.NET Web系统允许最终用户在某些情况下输入HTML格式的文本.在其中一些地方,我们希望保留所有标签,但剥去任何尾随的断点标签(但在文本正文中留下任何断点.)

最好的方法是什么?(我可以想办法做到这一点,但我确信它们不是最好的.)

bdu*_*kes 12

正如@Mitch所说,

//  using System.Text.RegularExpressions;

/// <summary>
///  Regular expression built for C# on: Thu, Sep 25, 2008, 02:01:36 PM
///  Using Expresso Version: 2.1.2150, http://www.ultrapico.com
///  
///  A description of the regular expression:
///  
///  Match expression but don't capture it. [\<br\s*/?\>], any number of repetitions
///      \<br\s*/?\>
///          <
///          br
///          Whitespace, any number of repetitions
///          /, zero or one repetitions
///          >
///  End of line or string
///  
///  
/// </summary>
public static Regex regex = new Regex(
    @"(?:\<br\s*/?\>)*$",
    RegexOptions.IgnoreCase
    | RegexOptions.CultureInvariant
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );
regex.Replace(text, string.Empty);
Run Code Online (Sandbox Code Playgroud)