python - Regex that matches all week day's name in a string -


i want match every week day in string words comma separated.

examples: "mon, thu, fry" should matched "mon, tue, sat" should matched "" should not matched "mon, tue, wed, thu, fri, sat, sun" should matched "foo, bar" should not matched

i came regex matches string containing week days:

^(mon|tue|wed|thu|fri|sat|sun)$ 

how can match them "indipendently"?

i using python3

if have ability use newer regex module, use recursive approach:

^((?:mon|tue|wed|thu|fri|sat|sun)(?:, )?)(?1)*$' 


in python be:

import regex re  string = """ mon, tue, fri mon, tue, sat mon, tue, wed, thu, fri, sat, sun foo, bar mon tue wed mon, wed """  rx = re.compile(r'^((?:mon|tue|wed|thu|fri|sat|sun)(?:, )?)(?1)*$') days = list(filter(lambda x: rx.match(x), string.split("\n"))) print(days) 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -