如何使用JQuery查找标记内的文本

如何使用JQuery查找标记内的文本,jquery,Jquery,嗨,我有一段如下 <p>The strength of the notion of the cultural biography, in my mind, is that it provides us with a way to escape from these preoccupations <xref>1990</xref>. The algorithm takes a set of earthly 1989 biographies as input a

嗨,我有一段如下

<p>The strength of the notion of the cultural biography, in my mind, is that it provides us with a way to escape from these preoccupations <xref>1990</xref>.  The algorithm takes a set of earthly 1989 biographies as input and produces a set of improved resurrection 1915 biographies as output.</p>

但是这段代码返回一个未标记的年份,我希望在段落中使用正则表达式来匹配所有长度为4的数字和前导和尾随空格

试试下面的解决方案

$document.readyfunction{ var regexp=/\s+\d{1,4}\s+/g; var txt=$'p'.text; 变量匹配,匹配=[]; 而match=regexp.exectxt!=null{ 匹配项。pushparseIntmatch[0]。替换/\s/g; } 控制台。日志匹配; }; 在我看来,文化传记概念的力量在于,它为我们提供了一种摆脱这些困扰的方法。该算法将一组1989年的地球传记作为输入,并生成一组改进的1915年复活传记作为输出。

$document.readyfunction{ var$container=$this.findxref.remove.text.match/\d+/g; var num=$this.findvalue.text.match/\d+/g.join,; console.log num; };

在我看来,文化传记概念的力量在于它为我们提供了一种摆脱这些困扰的方法1990年算法将一组1989年的尘世传记作为输入,并生成一组改进的1915年复活传记作为输出。

获取未标记的年份值

var untagged_19_20 = $(this).clone().find('xref').remove().end().text().match(/19+[0-9][0-9]/g);
var untagged_19_20 = untagged_19_20 + ',' + $(this).clone().find('xref').remove().end().text().match(/20+[0-9][0-9]/g);

谢谢,但我需要找到未标记的年份示例输出应该是1989年,1915@Swashichanged相应的逻辑。请在世界上测试无PLSLESJQuery:'var untaged_19_20=untaged_19_20.replace/19+[0-9][0-9]/g,'1';'如何使用替换here@Swashi您的解决方案仅适用于从19开始的年份,并且仅适用于您的文本。而使用此代码将适用于任何数字。顺致敬意,
var untagged_19_20 = $(this).clone().find('xref').remove().end().text().match(/19+[0-9][0-9]/g);
var untagged_19_20 = untagged_19_20 + ',' + $(this).clone().find('xref').remove().end().text().match(/20+[0-9][0-9]/g);