jQuery / Regex:删除所有p标签 [英] jQuery / Regex: remove all p tags
问题描述
我是Regex的新手,希望有人能够帮助我:
我有一个长字符串保存为变量。
该字符串包含纯文本和HTML标记,包含。 p标签。
如何使用正则表达式从我的字符串中删除所有p标签,包括p标签上的类和标识,但不会丢失文本内部?
字符串变量可以包含一个,多个或不包含p标签,但始终包含至少一些文本。
示例:
现在的样子:
var str =一些带有< p class ='myClass'>新的精彩文字段< / p为H.和更多的文字。
应该如何看:
var str =一些带有新段落和更多文本的精彩文本。
非常感谢Tim的帮助。
result = str.replace(/(< p [^>] +?> |< p> |< \ / p>)/ img,);
更新了正则表达式
I am new to Regex and hope someone can help me with the following:
I have a long string that is saved as a variable. The string contains plain text and HTML tags, incl. p tags.
How can I use Regex to remove all p tags from my string including classes and IDs on the p tags but without losing the text inside ? The string variable can contain one, multiple or no p tags but always contains at least some text.
Example: How it looks now:
var str = Some awesome text with a <p class='myClass'>new paragraph</p> and more text.
How it should look:
var str = Some awesome text with a new paragraph and more text.
Thanks for any help with this, Tim.
result = str.replace(/(<p[^>]+?>|<p>|<\/p>)/img, "");
updated regex
这篇关于jQuery / Regex:删除所有p标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!