Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #14417
| References | <mailman.653.1314870127.27778.python-list@python.org> <j3nmqm$vp4$1@solani.org> |
|---|---|
| Date | 2011-10-11 00:23 +0200 |
| Subject | Re: Regex to match all trailing whitespace _and_ newlines. |
| From | Dotan Cohen <dotancohen@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1871.1318285416.27778.python-list@python.org> (permalink) |
On Thu, Sep 1, 2011 at 13:30, Peter Otten <__peter__@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("<EOL>", "alpha \nbeta \r\n\ngamma\n")
> 'alpha<EOL>beta<EOL><EOL>gamma<EOL>'
>>>> sub("<EOL>", "alpha \nbeta \r\n\ngamma")
> 'alpha<EOL>beta<EOL><EOL>gamma<EOL>'
>>>> sub("<EOL>", "alpha \nbeta \r\n\ngamma\t")
> 'alpha<EOL>beta<EOL><EOL>gamma<EOL>'
>
Hi Peter, sorry for the _late_ reply.
It turns out that Anki stores newlines internally as <br>, since its
display model is based on HTML. Thanks, though!
--
Dotan Cohen
http://gibberish.co.il
http://what-is-what.com
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Regex to match all trailing whitespace _and_ newlines. Dotan Cohen <dotancohen@gmail.com> - 2011-09-01 12:42 +0300
Re: Regex to match all trailing whitespace _and_ newlines. Peter Otten <__peter__@web.de> - 2011-09-01 12:30 +0200
Re: Regex to match all trailing whitespace _and_ newlines. Dotan Cohen <dotancohen@gmail.com> - 2011-10-11 00:23 +0200
csiph-web