首页  编辑  

替换标记中的字符串

Tags: /C#/字符串处理/正则表达式/   Date Created:

using System . Text . RegularExpressions;

string S = @"a[abc]Zswang[/abc]b[abc] ;

Text = Regex . Replace(S, @"\[abc\][^\[]*\[\/abc\]" , @"" , RegexOptions . None); // abc

// or

string S = @"a<font size=9>Zswang</font>b<font size=10> ;

Text = Regex . Replace(S, @"<font[^>]*>[^<]*</font>" , @"" , RegexOptions . None); // abc

// or

string S = @"a[abc]Z[swang[/abc]b[abc] ;

Text = Regex . Replace(S, @"(\[abc\])(?!\[abc\]|\[/abc\])(.*?)(\[/abc\])" , @"" , RegexOptions . None); // abc