You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

移除HTML中重复ID的连续span元素,保留单个并合并文本

问题需求

处理一段HTML字符串时,需要实现以下操作:

  • 选中所有<span>元素
  • 移除连续排列的同ID重复<span>,仅保留一个
  • 将所有被移除的同ID<span>内的文本合并到保留的那个<span>中
  • 不得删除<span>元素之外的其他文本

示例

输入

<p>
  Hi,<span id="1">this is just a simple text and we</span>
  <span id="1">want to save me because i had a lot of</span>
  <span id="1">pressure on and i want to live a better life. 😭</span>
  I researched a lot about it but i could't find anything helpful
  <span id="2">just another rant. 😭</span>
</p>

输出

<p>
  Hi, 
  <span id="1">
      this is just a simple text and we want to save me because i had a lot of 
      pressure on and i want to live a better life 😭
  </span>
  I researched a lot about it but i could't find anything helpful
  <span id="2">just another rant. 😭</span>
</p>

内容的提问来源于stack exchange,提问作者Samyar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 16:30:57