应该为HTML标记使用什么正则表达式? [英] What regular expression should be used for HTML tags?
本文介绍了应该为HTML标记使用什么正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用空格替换字符串中的所有HTML标记。我应该使用什么正则表达式?
输入:
< td align = right > < br > < / td > < / tr > < tr > < < span class =code-leadattribute> td colspan < span class =code-keyword> = 2 > & nbsp; < / td > < / tr > < tr > < td colspan = 2 > 您好[FNm] [LNm]:< br > < br 跨度> <跨度class =code-keyword>> 感谢下载。
输出:
您好[FNm] [LNm] :谢谢你的下载。
帮我为此设计正则表达式。
string input = ' < td align =right>< br>< / td>< / tr>< tr>< td colspan =2>& nbsp;< / td>< / tr>< tr>< td colspan =2>您好[FNm] [LNm ]:< br>< br>感谢下载。;
string atr = Regex.Replace(输入,[我应该使用什么正则表达式模式],);
另外我想删除与HTML一起使用的所有关键字'\ n','\ r' div class =h2_lin>解决方案
访问这里...
一些正则表达式示例 [ ^ ]
试试这个:
string atr = Regex.Replace(输入, < /?。+?> , );
这用空格替换每个标签(开始标签和结束标签)。
我得到的另一个答案。如果有人提到这个问题可以试试这个:
< [^>] *>
I want to replace all the HTML tags in string with space. What regular expression should I use for that?
Input:
<td align="right"><br></td></tr><tr><td colspan="2"> </td></tr><tr><td colspan="2">Hi [FNm] [LNm]:<br><br>Thanks for downloading.
Output:
Hi [FNm] [LNm]: Thanks for downloading.
Help me to design regular expression for this.
string input='<td align="right"><br></td></tr><tr><td colspan="2"> </td></tr><tr><td colspan="2">Hi [FNm] [LNm]:<br><br>Thanks for downloading.";
string atr=Regex.Replace(input,[what regex pattern should I use]," ");
Also I want to remove '\n', '\r' n all of those keywords that are used with HTML
解决方案
visit here...
Some Regular Expressions Examples[^]
Try this:
string atr = Regex.Replace(input, "</?.+?>", " ");
This replaces every tag (start tags and end tags) with a space.
One more answer I got. If anybody referring this question can try this:
"<[^>]*>"
这篇关于应该为HTML标记使用什么正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文