On 24/02/06, John Zenger <[EMAIL PROTECTED]> wrote:
Franz Steinhaeusler wrote:
>
> Thank you all for the replies.
> But I still don't have a solution.
>
re.sub(r"\s+[\n\r]+", lambda x: x.expand("\g<0>"). \
     lstrip(" \t\f\v"),text).rstrip()


But I think your code is a lot easier to read.  :)

How about:

>>> linesep = '\n'
>>> text = 'erewr  \t  \r\nafjdskl  \r\n  \r\npythonlist'
>>> linesep.join([ x.rstrip() for x in text.replace('\r\n','\n').replace('\r','\n').split('\n') ])
'erewr\nafjdskl\n\npythonlist'

Which right-strips the line endings, tabs and spaces from the ends of lines in a string derived from either Windows, Mac and Unix  or mixed files

HTH :)



--

Tim Williams
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to