如何替换字符串中不在html标记中的所有期间? [英] How to replace all periods in a string that aren't in an html tag?

查看:86
本文介绍了如何替换字符串中不在html标记中的所有期间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要替换用户提交的文本段落中的所有句子,这些段落很可能是从微软Word文档中复制和粘贴的,因此文本将具有格式。



例如,从字中粘贴的文本如下所示:

 < p class =MsoNormalstyle = margin-bottom:5.75pt; text-indent:0.5in;>< span style =font-size:12.0pt; font-family:etc ... 
/ pre>

我需要编辑所有的期间不在这些标签内,并围绕他们放置span标签,所以我不能只抓住html和做。



:(

解决方案

//stackoverflow.com/questions/298750/how-do-i-select-text-nodes-with-jquery\">这个回答找到文本节点,然后对它们进行替换。



如果你有一个字符串,首先转换成文档片段。


I need to replace all periods in a user submitted paragraph of text that will most likely be copy and pasted from a microsoft word document so the text will have formatting on it.

For example, text pasted in from word looks like this:

<p class="MsoNormal" style="margin-bottom: 5.75pt; text-indent: 0.5in;"><span style="font-size:12.0pt;font-family: etc...

I need to edit all of the periods not within these tags and put span tags around them, so I can't just grab the html and do .replace.

:(

解决方案

Use this answer to find text nodes, then do the replace on them.

If you have it as a string, convert into document fragment first.

这篇关于如何替换字符串中不在html标记中的所有期间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆