Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>import re s = '''Aug 23, 2011 10:31:35 AM This is the start of the text. This is more Text. This is another line This is another line This is more. Aug 23, 2011 10:41:00 AM This is the next in the series. This is another line This is more Text. This is another line This is another line This is more. Aug 24, 2011 10:41:00 AM This is the next in the series. This is another line This is more Text. This is another line This is another line This is more. ''' months = '(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)' ch = '%s \d\d?, \d{4} \d\d:\d\d:\d\d (?:AM|am|PM|pm)' % months regx = re.compile('%s.*?(?=%s|\Z)' % (ch,ch), re.DOTALL) for x in regx.findall(s): print repr(x) print </code></pre> <p>result</p> <pre><code>'Aug 23, 2011 10:31:35 AM This is the start of the text.\n This is more Text.\nThis is another line\nThis is another line\n This is more.\n' 'Aug 23, 2011 10:41:00 AM This is the next in the series.\nThis is another line\n This is more Text.\nThis is another line\n This is another line\n This is more.\n' 'Aug 24, 2011 10:41:00 AM This is the next in the series.\nThis is another line\n This is more Text.\nThis is another line\n This is another line\n This is more. ' </code></pre> <p>Yes, you'll have to learn the regex tool (module <code>re</code>)</p> <p>update: a minimum of explanations:</p> <p>parens <code>(...)</code> define a group<br> without <code>?:</code>, it is a capturing group<br> <code>(?:......)</code> is a non capturing group</p> <p><code>(?=....)</code> means **after this point, there must be a portion of string matching what is symbolised after <code>?=</code> , but this portion isn't captured: that's the way to obtain a stop of the regex motor just before this portion, without capturing it; that allows too, and it is the more important, the regex motor to match again from the beginning of this stopping portion, otehrwise the latter would be consumed too</p> <p><code>re.DOTALL</code> is to make the symbol . (the dot) to match ALL the characters, comprised '\n' , which is not the case without this flag</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload