具有可变长度主匹配的负向前瞻

时间:2014-11-28 10:47:30

标签: python regex

我正在尝试生成一个匹配单个日期的正则表达式脚本,如果没有后跟',','和'或者'&'。例如,我希望匹配

on mondays

on monday

但不是

on mondays,

on mondays and

on mondays &

到目前为止,我有:

\b(?:on|in)\s+(?:weeknights?|weekends?|weekdays?|mornings?|afternoons?|nights?|evenings?|mondays?|tuesdays|wednesdays?|thursdays?|fridays?|saturdays?|sundays?|(?:(?:mon|tues?|weds?|thu(?:rs|r)?|fri|sat|sun)s?\.?))(?!(?:\,|\s+and\s+|\s+&\s+))

但是在

的情况下
on mondays,

它匹配

on monday

而不是根本没有匹配。关于如何解决这个问题的任何想法?

1 个答案:

答案 0 :(得分:0)

尝试在其中放置一个分词\b

on mondays?\b(?!\s*(and|[&,]))

http://regex101.com/r/yW6fL4/1