In [4]:
import re
In [8]:
s ='\n#here's a title\n\nhello world!!!\n\nPosted on 11-09-2014 02:32:30'
In [5]:
s ='\n#heres a title\n\nhello world!!!\n\nPosted on 11-09-2014 02:32:30\n'
In [6]:
# this grabs the title
re.findall(r'#.+\n',s)[0][1:-1]
Out[6]:
In [9]:
#this grabs the date
re.findall(r'Posted on .+\n',s)[0][10:-1]
In [14]:
#this grabs the date
re.findall(r'Posted on [\d\-\s:]+',s)
Out[14]:
In [15]:
re.findall(r'^[#\W+]',s)
Out[15]:
In [17]:
re.findall(r'^[\W+]',s)
Out[17]:
In [45]:
# result = re.findall(r'#.+\n(.*?)\n+Posted on .*?\n', s, re.MULTILINE | re.DOTALL)
result = re.search(r'#([^\n]+)\n+(.*)\n+(Posted on [^\n]*)', s, re.MULTILINE | re.DOTALL)
result
Out[45]:
In [47]:
regex = re.compile(r'#([^\n]+)\n+(.*)\n+(Posted on [^\n]*)', re.MULTILINE | re.DOTALL)
result = regex.search(s)
result
Out[47]:
In [ ]: