Javascript 捕获开始标记,但不捕获结束标记

Javascript 捕获开始标记,但不捕获结束标记,javascript,html,regex,regex-lookarounds,capturing-group,Javascript,Html,Regex,Regex Lookarounds,Capturing Group,我要分割父块,同时沿每个段的文本捕获嵌套标记: (?<tag>.)(?: href="(?<url>.+?)")?>(?<text>.+?)< 花了好几个小时,还没弄明白,我真的很感激你的建议。根据我在匹配信息框中看到的内容,我认为这是可行的: /(?:(?(?。+?)你能举例说明要捕获什么和不捕获什么吗?你已经给出了你的尝试和示例文本。但是你没有给出你想要获得什么的例子(我认为这与@Addis已经评论过的内容一致)。另外,我个人找到了该部分,但

我要分割父块,同时沿每个段的文本捕获嵌套标记:

(?<tag>.)(?: href="(?<url>.+?)")?>(?<text>.+?)<

花了好几个小时,还没弄明白,我真的很感激你的建议。

根据我在匹配信息框中看到的内容,我认为这是可行的:


/(?:(?(?。+?)你能举例说明要捕获什么和不捕获什么吗?你已经给出了你的尝试和示例文本。但是你没有给出你想要获得什么的例子(我认为这与@Addis已经评论过的内容一致)。另外,我个人找到了该部分,但我想要[…]:(有点复杂。你能用更多的词来表达你的意图吗?最后,我们为什么要关心示例标记?它对问题/答案有多重要?它必须是正则表达式吗?它通常不是XML/HTML解析的好工具,但浏览器有一些惊人的JavaScript工具,包括DOM,正是出于这个目的。@EnricoMariaDeAngelis我已经更新了这个问题,包括了我想要得到的结果。我还想包括一个源标记样本,它确实只有结果样本才有意义。@David784它必须是这样的,我将它用于我的HTML-to-pdf解析器。谢谢,伙计,这很有效。只有一个警告,它使用的是反向查找,不支持Safari的orted:(你能建议一种没有它的方法吗?@EdmondTamas,我想不出一种方法,原因是:如果你不想向后看(即匹配某个东西而不使用它),那么你必须使用它;但是,如果你使用

{
   "0":{
      match: "p>The <",
      tag: "p",
      url: null,
      text: "The "
   },
   "1":[
      match: "a href=\"https://www.legislation.gov.uk/ukpga/2010/23/contents\">UK Bribery Act<",
      tag: "a",
      url: "https://www.legislation.gov.uk/ukpga/2010/23/contents",
      text: "UK Bribery Act"
   ],
   "2":[
      match: "/a> (“the Act”) received Royal Assent in April 2010 and came into ... <",
      tag: null
      url: null,
      text: " (“the Act”) received Royal Assent in April 2010 and came into ... "
   ],
   "3":[
      match: "a href=\"http://www.oecd.org/daf/anti-bribery/ConvCombatBribery_ENG.pdf\">OECD anti-bribery Convention<",
      tag: "a",
      url: "http://www.oecd.org/daf/anti-bribery/ConvCombatBribery_ENG.pdf",
      text: "OECD anti-bribery Convention"
   ],
   "4":[
      match: "/a>. The Act outlined four prime offences, including the introduction ... <",
      tag: null,
      url: null,
      text: ". The Act outlined four prime offences, including the introduction ... "
   ],
   "5":[
      match: "b>rest is history<",
      tag: "b",
      url: null,
      text: "rest is history"
   ]
   ...
}
/(?:(?<tag>(?<!\/).)|(?:\/.))(?: href="(?<url>.+?)")?>(?<text>.+?)</gm