On Wed, 23 Feb 2011 21:11:53 -0500, monkeys paw wrote:

> if I have a string such as '<td>01/12/2011</td>' and i want to reformat
> it as '20110112', how do i pull out the components of the string and
> reformat them into a YYYYDDMM format?

data = '<td>01/12/2011</td>'
# Throw away tags.
data = data[4:-5]
# Separate components.
day, month, year = data.split('/')
# Recombine.
print(year + month + day)


No need for the sledgehammer of regexes for cracking this peanut.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to