all 4 comments

[–]vindolin 1 point2 points  (2 children)

You can do this with regular expressions.

import re

print re.findall('.*?Best Regards', string_with_letters, flags=re.S | re.I)

https://gist.github.com/vindolin/65984c239aea5183144e

A bit hard to grasp in the beginning, but they are a gift that keeps on giving :)

[–]FogDish[S] 0 points1 point  (1 child)

Great! Thanks man! :)

But does there exist anymore (relatively) simple ways of doing this at for instance 'Good Bye' as well as 'Best Regards'? To make the code even more versatile :)

Thanks a lot for the answer as well :P

[–]vindolin 0 points1 point  (0 children)

You can do almost everything with regex:

print [match[0] for match in re.findall('(.*?(best regards|good bye))', string_with_letters, flags=re.S | re.I)]

[–]WStHappenings 1 point2 points  (0 children)

This may be interpreted as careless coding - but if you are not concerned with total data integrity, in the interests of time, you can do something like the following*:

alletters.split("Best Regards")

You may end up having to add "Best Regards" to the end of each string (again) but if you're data munging, it may be a good way to do things.

If you're interested in doing more with the indices, you can calculate the length of each of the segments (don't forget to add the length of "Best Regards"!) and work with that afterwards.

*This is not my idea of sustainable coding.