如果它是相同的标签,则使用 javascript 裁剪第一个和最后一个标签
我正在尝试从字符串中删除标签:
"<p>string</p>" must be converted to "string"
我找到了简单裁剪第一个和最后一个标签或所有标签的解决方案,然后
"<p>string1</p><p>string2</p>" converts to "string1</p><p>string2"
我想检查字符串,例如
"IF last </p> tag is closing tag for first <p> tag THEN crop"
这可能与正则表达式有关吗? 如果不是,我认为公式一定是这样的: ;标签等于 1,
我开始从字符串末尾对这些数字求和,并在总和等于零时停止。如果我停止的点是字符串的末尾,那么它就是一个标签,我需要裁剪它。否则就是不同的标签。 但我不知道如何编码,请帮忙。
I'm trying to delete tags from string:
"<p>string</p>" must be converted to "string"
I found solution for simply cropping first and last tags or all tags and then
"<p>string1</p><p>string2</p>" converts to "string1</p><p>string2"
I want to check string, something like
"IF last </p> tag is closing tag for first <p> tag THEN crop"
Is this possible to do with regex?
If no, I think formula must be something like: <p> tags equals 1, </p> equals -1.
I start to sum this numbers from end of string and stop when sum equals zero. If point where I stop is the end of string then it's one tag and I need crop it. Otherwise it's different tags.
But I don't know how to code it, help please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道 @drachenstern 发布的评论几乎回答了你的问题,但仍然如此。您可以在
replace()
函数旁边使用相当简单的正则表达式。这个小功能应该可以解决问题。I know @drachenstern has posted that comment pretty much answering your question but still. You can use a fairly simple regex along side the
replace()
function. This little function should do the trick.我想我把这个任务搞得太复杂了。我忘记了
标签不能位于另一个
中。
然后我可以简单地检查一下,
谢谢您的回答,对愚蠢的问题感到抱歉,我只是需要更多的睡眠。
I think I made this task too complicated. I forgot that
<p>
tag can't be in another<p>
.And then I can simply do check
Thanks for your answers and sorry about stupid question, I just need more sleeping.