我是一名 cs 新手,目前正在努力获得这样的 python 正则表达式模式:
it must contain "stop (at most 10 words inbetween) mail" and do not contain "mail stop".
也就是说,
"please stop the mail, and I want the mail stop" AND "please stop the mail stop" would be rejected. ("mail stop" pattern spotted)
"please stop the mail" AND "please stop the mail, I want the mail to stop" both would be accepted.(only "stop ~ mail" pattern is seen, and no "mail stop")
我目前拥有的是:
import re
pattern = re.compile("(?=(stop\s+(\w+\s+){0,10}mail[^\s]*))(?!mail\s+stop)")
print(pattern.search("please stop the mail, I want the mail to stop").group())
但不知何故,它不能按我想要的方式工作。
任何帮助,将不胜感激。
埃里克