开发者

C# How to remove text between BBCode

How to remove all text between BBCode Quotation (including BBCode itself):

[quote date=2011-07-02 14:43:53 user=test link=1]blabla[/quote]

I must add that between tags can be text with HTML tags for formating. My current attempt looks like:

Regex regex = new Regex(@"[开发者_StackOverflow社区quote+].+?[/\+quote]");

Well it's almost working.


You may try the following regex:

@"\[quote.*\].*?\[/quote\]"

Note that you have to escape square brackets in a regex.


Since your BBCode blocks contains attributes, a simple + won't suffice to cover everything. + means to repeat the specified range of characters, in this case e.

On the top of my head, I'd try something like this:

 \[quote([^\[]*)\](.*?)\[\/quote\]

Please bear in mind that I have not tested this for C#, where the syntax might be different depending on the interpreter. Also note that I've added selection groups so that you'd be able to examine the result of each expression. As @Howard answered, [ and ] are reserved symbols and consequently needs to be escaped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜