使用正则表达式在连词 'and' 之前插入后继词

Insert the succeeded word before conjunction 'and' using regex

输入字符串:

However, the gene of hBD-1 and LL-27 expression was not affected by cancer in both acne and non-acne patients.

预期输出字符串:

However, the gene of hBD-1 expression and LL-27 expression was not affected by cancer in both acne patients and non-acne patients.

代码:

import re
string_a = "However, the gene of hBD-1 and LL-27 expression was not affected by cancer in both acne and non-acne patients."
print(string_a)
print('\n')
output = re.sub(r'\b(\w+-(\d+|[A-Za-z]+))\b(?! [A-Za-z]+\b)', r'\b( [A-Za-z]+)\b', string_a)
print(output)

我没有得到准确的输出字符串。请查看我的代码并提出或修改解决方案。

我会在此处使用 re.sub 选择性地用其自身后跟文本 expression 替换任何基因术语,对于那些后面没有此文本的基因。

inp = "However, the gene of hBD-1 and LL-27 expression was not affected by acnes."
output = re.sub(r'\b(\w+-\d+)\b(?! expression\b)', r' expression', inp)
print(output)

这会打印:

However, the gene of hBD-1 expression and LL-27 expression was not affected by acnes.