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("", "a

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 \

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 ent