Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12556
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Regex to match all trailing whitespace _and_ newlines. |
| Followup-To | comp.lang.python |
| Date | 2011-09-01 12:30 +0200 |
| Organization | None |
| Message-ID | <j3nmqm$vp4$1@solani.org> (permalink) |
| References | <mailman.653.1314870127.27778.python-list@python.org> |
Followups directed to: comp.lang.python
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>'
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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