Re: how to remove BR using replace function?

2006-02-10 Thread Duncan Booth
Sion Arrowsmith wrote:

 Duncan Booth  [EMAIL PROTECTED] wrote:
Although I generally advise against overuse of regular expressions,
this is one situation where regular expressions might be useful: [ ...
] 
 nobr = re.compile('\W*br.*?\W*', re.I)
 
 Agreed (on both counts), but r'\s*br.*?\s*' might be better
 (consider what happens with an unfortunate... br in the middle
 if you use \W rather than \s).
 

Yes, I don't really know why I wrote \W when I obviously meant \s. Thanks 
for correcting that.

Even better might be r'(\s*br.*?)+\s*' to get multiple runs of br tags.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to remove BR using replace function?

2006-02-09 Thread Rinzwind
Works for me.

 txt = an unfortunate br in the middle
 print txt.replace(br, )
an unfortunate  in the middle
 


Though I don't like the 2 spaces it gives ;)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to remove BR using replace function?

2006-02-09 Thread Duncan Booth
Rinzwind wrote:

 Works for me.
 
 txt = an unfortunate br in the middle
 print txt.replace(br, )
 an unfortunate  in the middle
 
 
 
 Though I don't like the 2 spaces it gives ;)
 
Although I generally advise against overuse of regular expressions, this is 
one situation where regular expressions might be useful: the situation is 
simple enough not to warrant a parser, but apart from the whitespace a br 
tag could have attributes or be written in xhtml style br /. Also judging 
by the inconsistency between the OP's subject line and his original 
question he doesn't seem sure whether the tag is br or BR or even Br.

 import re
 nobr = re.compile('\W*br.*?\W*', re.I)
 nobr.sub(' ', an unfortunate br / in the middle)
'an unfortunate in the middle'
 nobr.sub(' ', an unfortunate BR in the middle)
'an unfortunate in the middle'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to remove BR using replace function?

2006-02-09 Thread Albert Leibbrandt


Rinzwind wrote:

Works for me.

  

txt = an unfortunate br in the middle
print txt.replace(br, )


an unfortunate  in the middle
  



Though I don't like the 2 spaces it gives ;)

  

so use regex and replace both the double spaces and the br

cheers
albert

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to remove BR using replace function?

2006-02-09 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
 i have some html that looks like this
 
 
 address style=color:#34 main,br Boston, MA/address
 
 and i am trying to use the replace function to get rid of the Br that
 i scrape out using this code:
 
 for oText in incident.fetchText( oRE):
 strTitle += oText.strip()

Why concatening ?

 strTitle = string.replace(strTitle,'br','')

Use strTitle.replace('br', '') instead. And BTW, hungarian notation is
evil, so:
for text in incident.fetchText(...):
   title = text.strip().replace('br', '')



 but it doesn't seem to remove the br

it does :

Python 2.4.2 (#1, Feb  9 2006, 02:40:32)
[GCC 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type help, copyright, credits or license for more information.
 s = 'address style=color:#34 main,br Boston, MA/address'
 s.replace('br', '')
'address style=color:#34 main, Boston, MA/address'


The problem is obviously not with str.replace(), as you could have
figured out by yourself very easily.

 any ideas?

yes: post the minimal *running* code that exhibit the problem.

Your problem is probably elsewhere, and given some of previous posts
here ('problems writing tuple to log file' and 'indentation messing up
my tuple?'), I'd say that a programming101 course should be your first
move.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to remove BR using replace function?

2006-02-09 Thread Sion Arrowsmith
Duncan Booth  [EMAIL PROTECTED] wrote:
Although I generally advise against overuse of regular expressions, this is 
one situation where regular expressions might be useful: [ ... ]
 nobr = re.compile('\W*br.*?\W*', re.I)

Agreed (on both counts), but r'\s*br.*?\s*' might be better
(consider what happens with an unfortunate... br in the middle
if you use \W rather than \s).

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

how to remove BR using replace function?

2006-02-08 Thread localpricemaps
i have some html that looks like this


address style=color:#34 main,br Boston, MA/address

and i am trying to use the replace function to get rid of the Br that
i scrape out using this code:

for oText in incident.fetchText( oRE):
strTitle += oText.strip()
strTitle = string.replace(strTitle,'br','')

but it doesn't seem to remove the br

any ideas?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to remove BR using replace function?

2006-02-08 Thread Dylan Moreland
I think you want to use the replace method of the string instance.
Something like this will work:

# See http://docs.python.org/lib/string-methods.html#l2h-196
txt = an unfortunate br in the middle
txt = txt.replace(br, )

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to remove BR using replace function?

2006-02-08 Thread localpricemaps
tried that, didn't work for me

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to remove BR using replace function?

2006-02-08 Thread localpricemaps
nope didn't work

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to remove BR using replace function?

2006-02-08 Thread Dylan Moreland

[EMAIL PROTECTED] wrote:
 nope didn't work

Could you be more specific about the error? Both my example and yours
work perfectly on my box.

-- 
http://mail.python.org/mailman/listinfo/python-list