On Tue, 20 Jul 2010 14:08:32 +0100, Peter Westlake wrote:
> On Tue, 20 Jul 2010 16:58 +0530, "Puneeth" <[email protected]> wrote:
> Here's a Pythonic way to do it, tested:
> import re
> my_string = "Hello\nWorld"
> pattern = re.compile('^',re.MULTILINE)
> my_new_string = re.sub(pattern, '> ', my_string)
> This still might not be quite right, as it will turn "Hello\nWorld\n"
> into "> Hello\n> World\n> ". Avoid that by using a negative lookahead
> for the end of the string:
> my_string = "Hello\n\nWorld\n"
> pattern = re.compile('^(?!\Z)',re.MULTILINE)
> my_new_string = re.sub(pattern, '> ', my_string)
> print my_new_string
> gives:
>> Hello
>>
>> World
Although python does not recommend TIMTOWTDI, but I would
use the following function
s = lambda str: ''.join(['< ' + s for s in str.splitlines(True)])
s("Hello\n\nWorld\n")
I think it is much nicer and clearer to me -- probably
because I use a lot of haskell. And the following is the
function s in haskell
s = unlines . map ("< " ++) . lines
Just my 2c.
--
J c/* __o/*
X <\ * (__
Y */\ <
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
[email protected]
http://lists.gnu.org/mailman/listinfo/emacs-orgmode