正则表达式,用于替换句子中的引文标记(科学论文)



给出一个句子:

We used mallet toolkit (Mccallum, 2002) for CRF implementation and word2vec (Mikolov et. al, 2013) for word embedding.

我想用(引文(替换所有有效的引文标签

We used mallet toolkit (citation) for CRF implementation and word2vec (citation) for word embedding.

如何创建正则表达式以确保javascript上的模式(+text+,+year+)有效?

我使用:

sentence.replace(/(.*,d{4})/,'(citation)');
target.replace(/(.*,d{4})/,'(citation)');

工作https://regex101.com/,但在使用nodejs 运行时没有

你已经很接近了-你只需要?添加惰性量词:

(.*?,s+d{4})

我添加了s+,以清楚地表明那里有一个空间(在代码中很难看到(。

在regex101.com中,选择保存regex,它将为您提供一个链接,其中包含填充相关字段的输入,例如regex101示例。

最新更新