擅长:python、mysql、java
<p>如果无法安装任何模块,可以重新格式化表达式并检查组1是否为空:</p>
<pre><code>import re
rx = re.compile("(denies)?.*?(alcohol|etoh)\s*(abuse|dependence)")
sentences = ["alcohol abuse", "etoh abuse", "alcohol dependence", "etoh dependence",
"denies alcohol dependence", "denies smoking and etoh dependence", "denies [anything at all] and etoh abuse"]
def filterSentences(input):
m = rx.search(input)
if m and m.group(1) is None:
print("Yup: " + sent)
for sent in sentences:
filterSentences(sent)
</code></pre>
<p>这就产生了</p>
<pre><code>Yup: alcohol abuse
Yup: etoh abuse
Yup: alcohol dependence
Yup: etoh dependence
</code></pre>
<p>如果有超过<code>denies</code>(即<code>does not like...</code>),只需更改第一个标题组。你知道吗</p>