Javascript 如何匹配多个正则表达式';在它们之间进行替换

Javascript 如何匹配多个正则表达式';在它们之间进行替换,javascript,regex,Javascript,Regex,在用户提供的任何科学论文中,程序必须 查找: 1.a-数字引用,例如 不是从总结的文本中复制完整的句子,而是 方法压缩句子[1,4-6],或重新生成新句子 从无到有的句子[3] 1.b-论文末尾的APA参考&仅是作者姓名+年份 将数字转换为APA,例如 不是从总结的文本中复制完整的句子,而是 方法压缩句子(京2000;奈特和马库) 2000年;Sporeder和Lapata 2005年;Steinberger和Ježek 2006年),或 从头开始重新生成新句子(McKeown等人1999) 我

在用户提供的任何科学论文中,程序必须

  • 查找:
  • 1.a-数字引用,例如

    不是从总结的文本中复制完整的句子,而是 方法压缩句子[1,4-6],或重新生成新句子 从无到有的句子[3]

    1.b-论文末尾的APA参考&仅是作者姓名+年份

  • 将数字转换为APA,例如
  • 不是从总结的文本中复制完整的句子,而是 方法压缩句子(京2000;奈特和马库) 2000年;Sporeder和Lapata 2005年;Steinberger和Ježek 2006年),或 从头开始重新生成新句子(McKeown等人1999)

    我认为正则表达式的作用是:

    "\[(\d.*?)\]"
    
    用于数字引用

    "\d+([\.]([\ ])(([\D*])*([\,]))*([\ ][\w][\.]))|[\d]{4}"
    
    APA引文风格

    我的问题是如何替换第一个模式中的第二个模式?

    使用回调函数将数字字符串(逗号分隔,可能是一个范围)拆分为一个数字数组。然后循环浏览这些数字,并使用其他正则表达式查找作者/年份。然后连接这些字符串并将其返回以进行替换

    var string = `Instead of reproducing full sentences from the summarized text, these methods either compress the sentences [1, 4-6], or re-generate new sentences from scratch [3].
    1. Jing, H.: Sentence Reduction for Automatic Text Summarization. In Proceedings of the 6th Applied Natural Language Processing Conference, Seattle, USA, 2000, pp. 310–315.
    3. McKeown et al: Sentence Reduction for Automatic Text Summarization. In Proceedings of the 6th Applied Natural Language Processing Conference, Seattle, USA, 1999, pp. 310–315.
    4. Knight and Marcu.: Sentence Reduction for Automatic Text Summarization. In Proceedings of the 6th Applied Natural Language Processing Conference, Seattle, USA, 2000, pp. 310–315.
    5. Sporleder and Lapata: Sentence Reduction for Automatic Text Summarization. In Proceedings of the 6th Applied Natural Language Processing Conference, Seattle, USA, 2005, pp. 310–315.
    6. Steinberger and Ježek: Sentence Reduction for Automatic Text Summarization. In Proceedings of the 6th Applied Natural Language Processing Conference, Seattle, USA, 2006, pp. 310–315.`;
    
    string.replace(/\[(\d[^\]]*)\]/g, function(matches, reference) {
        var numbers = [],
            authors = [];
    
        reference.split(/,\s*/g).forEach(function(number) {
            if(number.indexOf('-') !== -1) {
                var range = number.split('-');
                for(var i = range[0]; i <= range[1]; i++) {
                    numbers.push(i);
                }
            } else numbers.push(number);
        });
    
        numbers.forEach(function(number) {
            var regex = new RegExp(number + '\\. ([^:]+):.*?(\\d{4})'),
                matches = regex.exec(string);
            authors.push(matches[1] + ' ' + matches[2]);
        });
    
        return '(' + authors.join('; ') + ')';
    });
    
    var string=`这些方法不是从摘要文本中复制完整的句子,而是压缩句子[1,4-6],或者从头开始重新生成新句子[3]。
    1.Jing,H.:自动文本摘要的句子缩减。《第六届应用自然语言处理会议论文集》,美国西雅图,2000年,第310-315页。
    3.McKeown等人:自动文本摘要的句子缩减。《第六届应用自然语言处理会议论文集》,美国西雅图,1999年,第310-315页。
    4.奈特和马库:用于自动文本摘要的句子缩减。《第六届应用自然语言处理会议论文集》,美国西雅图,2000年,第310-315页。
    5.Sporleder和Lapata:用于自动文本摘要的句子缩减。第六届应用自然语言处理会议论文集,美国西雅图,2005年,第310-315页。
    6.Steinberger和Ježek:自动文本摘要的句子缩减。第六届应用自然语言处理会议论文集,美国西雅图,2006年,第310-315页;
    string.replace(/\[(\d[^\]]*)\]/g,函数(匹配项,引用){
    变量数=[],
    作者=[];
    reference.split(/,\s*/g).forEach(函数(编号){
    if(number.indexOf('-')!=-1){
    变量范围=编号。拆分('-');
    
    对于(var i=范围[0];i正则表达式如何将
    [1,4-6]
    更改为
    (Jing 2000;Knight和Marcu 2000;Sporleder和Lapata 2005;Steinberger和Ježek 2006)
    ?!?论文中将有参考文献部分,如:1.Jing,H:自动文本摘要的句子缩减。在《第六届应用自然语言处理会议论文集》,美国西雅图,2000年,第310-315页。我可以匹配作者和年份。但是我如何用匹配的字符串替换数字对不起,我错过了答案“论文结尾的APA参考”…这是一个家庭作业吗?因为通常的解决方案是“有人几乎保证已经写了这段代码,找到它,而不是重新发明轮子”。