[Tutor] lstrip() question

Tim Johnson tim at johnsons-web.com
Mon Feb 2 17:29:33 EST 2004


* don arnold <darnold02 at sprynet.com> [040202 13:22]:
> ----- Original Message -----
> From: "Karl Pflästerer" <sigurd at 12move.de>
> To: <tutor at python.org>
> Sent: Monday, February 02, 2004 3:17 PM
> Subject: Re: [Tutor] lstrip() question
> 
> 
> >
> > I would use a regexp.
> >
> > >>> tmp1 = '<br>real estate broker courtesy'
> > >>> import re
> > >>> re.sub('^<br>*', '', tmp1)
> > 'real estate broker courtesy'
> > >>> tmp1 = 'real estate broker courtesy'
> > >>> re.sub('^<br>*', '', tmp1)
> > 'real estate broker courtesy'
> >
> >    Karl
> '<br>real estate<br>broker<br>'
> 
> I don't know much about regexes, but is this because only the very first
> occurrence is considered to be at the beginning of the line? I'm sure there
> is a regex way to do it, but you could just use a simple loop and
> startswith():
> 
> >>> tmp2 = tmp
> >>> while tmp2.startswith('<br>'): tmp2 = tmp2[4:]
> >>> tmp2
> 'real estate<br>broker<br>'
> >>> tmp2 = '<br><br><br>'
> >>> while tmp2.startswith('<br>'): tmp2 = tmp2[4:]
> >>> tmp2
 
 Actually what I am *really* looking for is a way to
 strip either specific tags (like '<br>' from the
 left *or* any number of tags. I'm a regex dunce
 myself, so am researching patterns as we speak,
 but your iteration is kind of what I have in mind.
 thanks!
 tj
-- 
Tim Johnson <tim at johnsons-web.com>
      http://www.alaska-internet-solutions.com



More information about the Tutor mailing list