我正在努力找出各种术语的出现,而在这些术语之前没有另一组术语。通常,如果我在前面的组中有一个术语,我可以使用负的查找,但是在Python中有一个零宽度的假设,但情况似乎并非如此。我看到的唯一解决方案是运行两个正则表达式,一个用于显示我正在寻找的内容,另一个用于确认前面的组项不存在。必须有一种更优雅和更有效的方法来做到这一点。有人能帮忙吗?
测试句是:
10 day trip excludes flights确保由于“航班”一词前面有“排除”而不匹配的正则表达式如下:
(?:without|not including|doesn\'?t include|exclud(?:es|ing))\s*(?:flights?(?:\s+tickets)?|airfare|airline tickets?)但是,我要保证列入某些案文。我可以通过以下几点来证实这一点:
(?:flights?(?:\s+tickets)?|airfare|airline tickets?)因此,这将匹配“包括机票”和“机票”,而不是“没有机票”。
匹配字符串的一些示例如下:
including flights
includes flights
plus flights
flights are included
including airfare
and airfare一些不匹配字符串的示例如下:
not including flights
flights are not included
excluding flights
without airfare发布于 2014-08-21 18:40:26
你可以试试下面的正则表达式,
^(?=.*?(?:flights|airfare))(?:(?!without|not includ(?:ing|ed)|doesn\'?t include|exclud(?:es|ing)).)*$演示
https://stackoverflow.com/questions/25431311
复制相似问题