I have some output from a CAS and I want to split up the stuff into three, here is some sample output:
' 1+2;\r\n\r(%o2) 3\r\n(%i3) '
'?\r\n\r\n\rpos;\r\n\r(%o1) 0\r\n(%i2) '
I'd like to separate the output into three parts:
\r\n\(%i\d+\)\r\n\(%i\d+\) to always be alone in the final part. how would I separate them? I'm having trouble creating the code to do that.
EDIT: I'd like the semicolon to be retained even after separating the sections.
This should do what you have requested:
re.findall('^([^;]+);(.*)(\r\n\(%i\d+\).+)$', text, re.S)
To include the semicolon in the first group, just add it to the grouping parenthesis:
re.findall('^([^;]+;)(.*)(\r\n\(%i\d+\).+)$', text, re.S)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With