我在下面的 XML 文件链接中有一个文本
<p>The artificial and industrial uses <xref>1989</xref> of microorganisms for material production have a long history of more than a thousand years. Recently, genetic operations have been widely applied to improve production. Two generally considered <xref>approaches, 2017</xref> introduce enzymes that have higher activities from other organisms or species and introduce enzymes to realize metabolic pathways that do not naturally occur in the microorganisms. The former method is popular because its operation is simpler and improvements are more predictable than <xref>(2001)</xref> with the latter method. <xref>2013</xref> Conventional gene modifications using ultraviolet or other radiation types are easy to achieve and have been widely applied in many industries. Nevertheless, the efficiency of such improvements is quite low because gene modifications occur accidentally and uncontrollably, and progress is made serendipitously. Therefore, gene introduction is currently used along with conventional methods.</p>
我需要在<xref>
元素中的所有元素之前获取文本<p>
。
var $element = $xml.find("p").addBack("p");
$element.each(function()
{
//code here
});
输出像
<p>The artificial and industrial <u>uses <xref>1989</xref></u> of microorganisms for material production have a long history of more than a thousand years. Recently, genetic operations have been widely applied to improve production. Two generally <u>considered <xref>approaches, 2017</xref></u> introduce enzymes that have higher activities from other organisms or species and introduce enzymes to realize metabolic pathways that do not naturally occur in the microorganisms. The former method is popular because its operation is simpler and improvements are more predictable <u>than <xref>(2001)</xref></u> with the latter <u>method. <xref>2013</xref></u> Conventional gene modifications using ultraviolet or other radiation types are easy to achieve and have been widely applied in many industries. Nevertheless, the efficiency of such improvements is quite low because gene modifications occur accidentally and uncontrollably, and progress is made serendipitously. Therefore, gene introduction is currently used along with conventional methods.</p>
我浏览了很多问候在元素之前找到文本但我没有得到解决方案。请提前提出解决方案谢谢
您不应使用正则表达式解析 html,因为 html 可能具有导致意外行为的嵌套结构。
但是正如我在您的情况下看到的那样,它是简单的非嵌套情况,因此您可以使用此正则表达式,
([\w.]+\s+(?:<xref>.*?<\/xref>))
捕获一个单词(包括点)后跟xref
标签并将其替换为
<u>\1</u>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句