使用jquery/javascript在客户端格式化html数据

使用jquery/javascript在客户端格式化html数据,javascript,jquery,html,regex,Javascript,Jquery,Html,Regex,我需要一个正则表达式,它将处理文本编辑器中输入的文本格式 看到这个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

我需要一个正则表达式,它将处理文本编辑器中输入的文本格式

看到这个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:&quot;Times-Roman&quot;,&quot;serif&quot;;mso-bidi-font-family:
 Times-Roman;color:#1B1E20">-- Michael Hirst</span></b><span style="font-size:
14.0pt;font-family:&quot;Times-Roman&quot;,&quot;serif&quot;;mso-bidi-font-family:Times-Roman;
color:#1B1E20">, creator, writer, and executive producer,&nbsp;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_标记一样

 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);

请参见数据来自文本编辑器。而且那里总是不正常的。可以有任何格式。我只想格式化它。正如我在问题中提到的那样。这是关于格式化html的。@Creator如果html数据只是在文本编辑器中,那么使用javascript或jquery如何帮助解决问题?当用户发布它时。我可以抓取他的输入并在客户端格式化,然后传递到服务器端@花里胡哨