请问将HTML代码转换为UBB代码的c#正则表达式要怎么写啊,我只有将UBB转换为HTML的C#正则表达式,相反的我就不知道了,网上搜的都是JS的,但是我的数据处理都是要在后台进行处理,望高手帮忙解答一下~~
以下是我UBB转换为HTML的代码:
- C# code
public string ubbtohtml(string content) //ubb转html { content = Regex.Replace(content, @"\r\n", "<br/>"); content = Regex.Replace(content, " ", " "); content = Regex.Replace(content, @"\[b\](.+?)\[/b\]", "<b>$1</b>"); content = Regex.Replace(content, @"\[i\](.+?)\[/i\]", "<i>$1</i>"); content = Regex.Replace(content, @"\[u\](.+?)\[/u\]", "<u>$1</u>"); content = Regex.Replace(content, @"\[p\](.+?)\[/p\]", "<p class='load'>$1</p>"); content = Regex.Replace(content, @"\[align=left\](.+?)\[/align\]", "<align='left'>$1</align>"); content = Regex.Replace(content, @"\[align=center\](.+?)\[/align\]", "<align='center'>$1</align>"); content = Regex.Replace(content, @"\[align=right\](.+?)\[/align\]", "<align='right'>$1</align>"); content = Regex.Replace(content, @"\[url=(?<url>.+?)]\[/url]", "<a href='${url}' target=_blank>${url}</a>"); content = Regex.Replace(content, @"\[url=(?<url>.+?)](?<name>.+?)\[/url]", "<a href='${url}' target=_blank>${name}</a>"); content = Regex.Replace(content, @"\[quote](?<text>.+?)\[/quote]", "<div class=quote>${text}</div>"); content = Regex.Replace(content, @"\[img](?<img>.+?)\[/img]", "<img src='${img}' alt=''/>"); content = content.Replace("[face1]", "<img src='../Images/emotion/1.png' style='width:14px; height:14px;' alt='' />"); content = content.Replace("[face2]", "<img src='../Images/emotion/2.png' style='width:14px; height:14px;' alt='' />"); content = content.Replace("[face3]", "<img src='../Images/emotion/3.png' style='width:14px; height:14px;' alt='' />"); content = content.Replace("[face4]", "<img src='../Images/emotion/4.png' style='width:14px; height:14px;' alt='' />"); content = content.Replace("[face5]", "<img src='../Images/emotion/5.png' style='width:14px; height:14px;' alt='' />"); content = content.Replace("[face6]", "<img src='../Images/emotion/6.png' style='width:14px; height:14px;' alt='' />"); content = content.Replace("[face7]", "<img src='../Images/emotion/7.png' style='width:14px; height:14px;' alt='' />"); content = content.Replace("[face8]", "<img src='../Images/emotion/8.png' style='width:14px; height:14px;' alt='' />"); content = content.Replace("[face9]", "<img src='../Images/emotion/9.png' style='width:14px; height:14px;' alt='' />"); return content; }
------解决方案--------------------------------------------------------
html千奇百怪的写法很难干净的转化为ubb的.
我随便用个html,用了网上的工具进行转化,没有一个能转化的.
------解决方案--------------------------------------------------------
同意一楼,除非只转换有限的几个。
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------