Can't make regex work with Python -
i need extract date in format of: dd month yyyy (20 august 2013). tried following regex:
\d{2} (january|february|march|april|may|june|july|august|september|october|november|december) \d{4}
it works regex testers (chcked several text - monday, 19 august 2013), seems python doesn't understand it. output is:
>>> ['august'] >>>
can please understand me why happening ?
thank !
did use re.findall
? default, if there's @ least 1 capture group in pattern, re.findall
return captured parts of expression.
you can avoid removing every capture group, causing re.findall
return entire match:
\d{2} (?:january|february|...|december) \d{4}
or making single big capture group:
(\d{2} (?:january|february|...|december) \d{4})
or, possibly more conveniently, making every component capture group:
(\d{2}) (january|february|...|december) (\d{4})
this latter form more useful if need process individual day/month/year components.
Comments
Post a Comment