I have a string:
JUL 28
(it outputs over two lines, so there must
You have a bunch of options here. You could go for an all-out xml parser like lxml, though you seem to want a domain-specific solution. I'd go with a multiline regex:
import re
rex = re.compile(r'(.*?)',re.S|re.M)
...
data = """
JUL 28 """
match = rex.match(data)
if match:
text = match.groups()[0].strip()
Now that you have text, you can turn it into a date pretty easily:
from datetime import datetime
date = datetime.strptime(text, "%b %d")