Using regex: Regex :How to remove repetition of the same string? on newest questions tagged regex – Stack Overflow

I’m trying to find the year from the date.
the dates are in the format

"Nov.-Dec. 2010"
"Aug. 30 2011-Sept. 3 2011"
"21-21 Oct. 1997"

my regular expression is
q = re.compile("\d\d\d\d")
a = q.findall(date)

so obviously in the list it has two items for a string like "Aug. 30 2011-Sept. 3 2011"

["2011","2011"]

i dont want a repetition, how do i do that?

See Answers


source: http://stackoverflow.com/questions/11735292/regex-how-to-remove-repetition-of-the-same-string
Using regex: using-regex



online applications demo