【问题标题】:Remove specific references like author from scientific publication从科学出版物中删除特定的参考文献,如作者
【发布时间】:2021-06-05 12:41:35
【问题描述】:

我之前看到过这个问题:python removing references from a scientific paper 这与我想要做的类似,但我仍然无法弄清楚如何去做,假设我的字符串我有这样的参考,例如:Poteete et al . (2010) 如何在 python 中使用正则表达式从字符串中删除它?

我尝试过的与上一个问题相似,但也许我忘记了某事:

sentence = "Moreover, we elaborate on how these methods have led to improved insights into the theoretical framework proposed by  Poteete et al. (2010)"
sentence = re.sub(r'(?:[\w \.])+[0-9]{4}','',sentence)

对此有什么想法吗?非常感谢您的帮助。

【问题讨论】:

    标签: python regex string


    【解决方案1】:

    如果名称以大写字符 A-Z 开头:

    [A-Z]\w*(?: +\w+)*\. \(\d{4}\)
    
    • [A-Z]\w* 匹配一个字符 A-Z 和可选单词 char
    • (?: +\w+)* 可选择重复 1+ 个空格和 1+ 个单词字符
    • \. 匹配.
    • \(\d{4}\) 匹配括号之间的 4 位数字

    您也可以使用\s,而不是匹配空格,但这也可以匹配换行符。

    Regex demo

    import re
     
    sentence = "Moreover, we elaborate on how these methods have led to improved insights into the theoretical framework proposed by  Poteete et al. (2010)"
    sentence = re.sub(r'[A-Z]\w*(?: +\w+)*\. \(\d{4}\)', '', sentence)
    print (sentence)
    

    输出

    Moreover, we elaborate on how these methods have led to improved insights into the theoretical framework proposed by  
    

    【讨论】:

    • 感谢您的回答,与此相关的一个小问题例如如果我有一句“在Poteete et al. (2010) 中,已经详细讨论了多种方法在实践中的使用,导致在修订后的集体行动和公地理论中,包括三个要素:个人决策、微观情境条件和更广泛的社会生态背景的特征。”怎么去掉?
    • @Erwinwin 模式匹配相同的部分,对吧? regex101.com/r/bX0kRz/1
    • 如果要匹配到第一个点regex101.com/r/fhMfue/1
    【解决方案2】:

    重新导入

    s = "Moreover, we elaborate on how these methods have led to improved insights into the theoretical framework proposed by Poteete et al. (2010) and Someone et al. (2010) and something"
    
    print (re.sub(r'[A-Z][a-z]+\set al\.\s\([0-9]{4}\)','',s))
    

    输出:

    Moreover, we elaborate on how these methods have led to improved insights into the theoretical framework proposed by  and  and something
    

    在这里您可以检测到“等”。后跟一个日期,前面是一个名称,第一个字母为大写”。然后将其删除。

    不用说这些操作大多是自定义的,具体取决于您的特定论文、编辑器格式化引用的方式等。所以无论如何这一定很痛苦。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-17
      • 2016-06-24
      • 2016-12-15
      • 2016-08-22
      • 2023-03-28
      相关资源
      最近更新 更多