Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '>>>>': 0.09; 'internally': 0.09; 'skip:\\ 10': 0.09; 'trailing': 0.09; 'newlines': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.16; 'thanks,': 0.18; 'received:74.125.82.174': 0.19; 'received:mail- wy0-f174.google.com': 0.19; 'cc:no real name:2**0': 0.20; 'trying': 0.21; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'sep': 0.23; 'thu,': 0.28; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'html.': 0.30; 'sub': 0.30; 'whitespace': 0.30; "skip:' 10": 0.30; 'stores': 0.34; 'model': 0.37; 'received:74.125.82': 0.38; 'received:google.com': 0.38; 'subject:: ': 0.39; 'received:74.125': 0.39; 'url:co': 0.63; 'otten': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=HrbxBxQJ+jfn91xVabxggfIFbWftuh7XTPbUaRrkQq0=; b=i2ygPc4kNxySubTs/gpCnJPJGgAWxG+d4M3qKgBWfDaosZ+uhzmw7sZnNkOILiMfiF 9O64NoxmIY6QesSkEv27udBr8TL7n2t/Ff+AHAnx8G8G5k5SVaRRSTRGYqTTPYMnWL/s rM0pT1BMsVB2WWBBDa6V53dfb+bZ9mnAfgjN4= MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 11 Oct 2011 00:23:35 +0200 Subject: Re: Regex to match all trailing whitespace _and_ newlines. From: Dotan Cohen To: Peter Otten <__peter__@web.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1318285416 news.xs4all.nl 2487 [2001:888:2000:d::a6]:47998 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:14417 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 =3D re.compile(r"\s*?(\n|$)").sub >>>> sub("", "alpha =C2=A0 \nbeta =C2=A0 \r\n\ngamma\n") > 'alphabetagamma' >>>> sub("", "alpha =C2=A0 \nbeta =C2=A0 \r\n\ngamma") > 'alphabetagamma' >>>> sub("", "alpha =C2=A0 \nbeta =C2=A0 \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! --=20 Dotan Cohen http://gibberish.co.il http://what-is-what.com