python用tex中的regex区分引用和方程

2024-04-20 05:29:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图删除一段文本中的所有引用-它们包含在括号中。因此,最简单的方法是删除括号中的所有内容。。。但括号里有些东西很重要,比如方程。。。 所以我想我可以去掉所有的括号,但是不是所有的引用都有一个括号。。。。 有人能告诉我谁应该使用python表达式来区分以“(Author[possible et al.],year)”格式指定的公式和引用吗

删除包含内容的括号的示例:

file=open("polymer_model.txt", "r")
mystring = file.read()
def a(test_str):
    ret = ''
    skip = 0
    for i in test_str:
        if i == '(':
            skip += 1
        elif i == ')'and skip2c > 0:
            skip -= 1
        elif skip == 0:
            ret += i
    return ret


x = a(mystring)

尝试删除包含“et al:”的所有包含括号的内容的示例:

x=re.sub(r'(\w+ et al.\)s?','',x)

It is assumed that the average twisting energy is equal to (1/2)kT , we also have Teff = (C/kl).(rmsd(Tw))2 (Munteanu et al., 1998; Olson, 1996; Olson and Zhurkin, 2000). However this model is somewhat rudimentary according to other studies which prefer the equation: w∝exp(−E/kT) (Schlick, 1995)

应该是:

It is assumed that the average twisting energy is equal to (1/2)kT , we also have Teff = (C/kl).(rmsd(Tw))2. However this model is somewhat rudimentary according to other studies which prefer the equation: w∝exp(−E/kT)


Tags: thetotest示例内容modeliset
1条回答
网友
1楼 · 发布于 2024-04-20 05:29:25

我会尝试以下正则表达式:

\([A-Z]\w+[^\)]+?, (18|19|20)[0-9]{2}\)
  • \(括号字符
  • 作者应该以大写字母开头
  • \w+其他作者姓名
  • [^\)]+?除右括号外的所有内容
  • ,(19 | 20)[0-9]{2}逗号,后跟年份。如果你有1900年以前出版的书,你必须加上年份
  • \)括号字符

但这只是一个很好的猜测。可能有与此正则表达式匹配的公式或不匹配的引用。但我认为, year部分在大多数情况下都应该这样做

您可以在这里尝试更多示例: https://regex101.com/r/AKmfdr/2

相关问题 更多 >