我需要一个正则表达式来处理文本编辑器中输入的文本的格式。
查看此 html
<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt;line-height:
normal;mso-pagination:none;mso-layout-grid-align:none;text-autospace:none;text-align:center;"><b><span style="font- size:14.0pt;font-family:"Times-Roman","serif";mso-bidi-font-family:
Times-Roman;color:#1B1E20">-- Michael Hirst</span></b><span style="font-size:
14.0pt;font-family:"Times-Roman","serif";mso-bidi-font-family:Times-Roman;
color:#1B1E20">, creator, writer, and executive producer, Vikings</span><o:p></o:p></p>
预期输出:
<p style="text-align:center;"><span>--Michael Hirst</span></b><span>creator, writer, and executive producer,Vikings</span>
我需要从 html 中删除类属性。对于内联样式,我只需要文本对齐除外。 格式化后,我需要像我们在 php 中使用 strip_tags 那样除去一些标签
strip_tags($html,"<b><h2><h3><h4><strong><div><p><br><ul><li><ol><blockquote>")
执行此操作的正则表达式是什么。我是这个正则表达式的新手!
最佳答案
不要尝试使用正则表达式解析 html。搜索一下 SO - 有很多例子可以说明为什么不这样做。当您使用 jquery 标记您的问题时,您可以使用类似这样的内容作为起点:
var $html = $('.MsoNormal + span').html();
$('p').css('text-align','center').append($html);
关于javascript - 使用 jquery/javascript 在客户端格式化 html 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24160857/