如何使用正则表达式拆分HTML/XML,以便只使用JavaScript的同级?

如何使用正则表达式拆分HTML/XML,以便只使用JavaScript的同级?,javascript,regex,xml,Javascript,Regex,Xml,我有一些文字: <p>I hope that this works!</p> <p>Now that this is in, let's see!</p><p>I hope that bold <strong>works too</strong>!</p> <p>Will this works</p><ol><li>First item</li&g

我有一些文字:

<p>I hope that this works!</p> <p>Now that this is in, let's see!</p><p>I hope that bold <strong>works too</strong>!</p>
<p>Will this works</p><ol><li>First item</li><li>Second item</li><li>Third item</li></ol>
我希望这能奏效

现在,这是在,让我们看看

我希望bold也能起作用

第一项有效吗第二项有效吗第三项有效吗
我想把它分成:

<p>I hope that this works!</p>
我希望这能奏效

现在,这是在,让我们看看

我希望bold也能起作用

  • 第一项
  • 第二项
  • 第三项

  • 我不想拆分任何子元素,只拆分兄弟元素?

    解析类似于X/HTML的字符串的首选方法是使用

    conststr=`我希望这能奏效

    现在,这是在,让我们看看

    我希望bold也能起作用

    这样行吗

  • 第一项
  • 第二项
  • 第三项
  • `; const doc=new DOMParser().parseFromString(str,“text/html”);
    console.log(doc.body.children)
    Is
    DOMParser
    fast?@Shamoon如果您发现浏览器在解释和创建。这是您可以使用的第一件最好的东西——不仅用于特定任务,而且在您需要将字符串解析为实际文档时(这绝不是RegExp作业)。
    <p>Now that this is in, let's see!</p><p>I hope that bold <strong>works too</strong>!</p>
    
    <ol><li>First item</li><li>Second item</li><li>Third item</li></ol>