Re: Regex to match all trailing whitespace _and_ newlines.

2011-10-10 Thread Dotan Cohen
On Thu, Sep 1, 2011 at 13:30, Peter Otten <__pete...@web.de> wrote:
> Dotan Cohen wrote:
>
>> In the terrific Anki [1] application I am trying to remove trailing
>> whitespace from form fields. This is my regex:
>> [\n+\s+]$
>
> My attempt:
>
 sub = re.compile(r"\s*?(\n|$)").sub
 sub("", "alpha   \nbeta   \r\n\ngamma\n")
> 'alphabetagamma'
 sub("", "alpha   \nbeta   \r\n\ngamma")
> 'alphabetagamma'
 sub("", "alpha   \nbeta   \r\n\ngamma\t")
> 'alphabetagamma'
>

Hi Peter, sorry for the _late_ reply.

It turns out that Anki stores newlines internally as , since its
display model is based on HTML. Thanks, though!


-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regex to match all trailing whitespace _and_ newlines.

2011-09-01 Thread Peter Otten
Dotan Cohen wrote:

> In the terrific Anki [1] application I am trying to remove trailing
> whitespace from form fields. This is my regex:
> [\n+\s+]$

My attempt:

>>> sub = re.compile(r"\s*?(\n|$)").sub
>>> sub("", "alpha   \nbeta   \r\n\ngamma\n")
'alphabetagamma'
>>> sub("", "alpha   \nbeta   \r\n\ngamma")
'alphabetagamma'
>>> sub("", "alpha   \nbeta   \r\n\ngamma\t")
'alphabetagamma'

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


Regex to match all trailing whitespace _and_ newlines.

2011-09-01 Thread Dotan Cohen
In the terrific Anki [1] application I am trying to remove trailing
whitespace from form fields. This is my regex:
[\n+\s+]$

Actually, even simplifying it to [\n] or [\r\n] is not matching any
newlines! What might be the cause of this? Note that I am not entering
the regex in Python code, I am entering it in a regex-supporting
Find/Replace dialogue in Anki. Anki is written in Python.

Thanks.

[1] ankisrs.net

-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
-- 
http://mail.python.org/mailman/listinfo/python-list