473,606 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to remove <BR> using replace function?

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.fetchT ext( oRE):
strTitle += oText.strip()
strTitle = string.replace( strTitle,'<br>' ,'')

but it doesn't seem to remove the <br>

any ideas?

Feb 9 '06 #1
10 13940
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("<b r>", "")

Feb 9 '06 #2
tried that, didn't work for me

Feb 9 '06 #3
nope didn't work

Feb 9 '06 #4

lo************@ gmail.com wrote:
nope didn't work


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

Feb 9 '06 #5
Works for me.
txt = "an unfortunate <br> in the middle"
print txt.replace("<b r>", "") an unfortunate in the middle

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

Feb 9 '06 #6
Rinzwind wrote:
Works for me.
txt = "an unfortunate <br> in the middle"
print txt.replace("<b r>", "") 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'
Feb 9 '06 #7


Rinzwind wrote:
Works for me.
txt = "an unfortunate <br> in the middle"
print txt.replace("<b r>", "")

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

Feb 9 '06 #8
lo************@ gmail.com 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.fetchT ext( oRE):
strTitle += oText.strip()
Why concatening ?
strTitle = string.replace( strTitle,'<br>' ,'')
Use strTitle.replac e('<br>', '') instead. And BTW, hungarian notation is
evil, so:
for text in incident.fetchT ext(...):
title = text.strip().re place('<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 'o****@xiludom. gro'.split('@')])"
Feb 9 '06 #9
Duncan Booth <du**********@s uttoncourtenay. org.uk> 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 -- si***@chiark.gr eenend.org.uk -- 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
Feb 9 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7856
by: fis | last post by:
Hi all, I've problem because there are needed break lines in my texts on the web site but i can't do it :( My pipeline looks like: XMS -> I18N -> XSLT -> HTML I have lot of texts in my "languages" files and these are describes for things on my website. Example text looks like this:
6
12148
by: Lasse | last post by:
I have done this simple function, it seems to work as intended, to solve a problem i have had for a while. I couldnt find any sample around that was working for me. I would like to test it with you and see if there are any improvments that i should make ;-) It should be fast and if possible compatible with todays modern browser-standards. It should be activated by the onload-event. This is my code, free for all to use:
7
19115
by: noor.rahman | last post by:
I have an XML file that stores data from an HTML form. I use XSL to display the data in HTML format. The data may have newline characters. However, XSL is not displaying the newlines properly in the browser. I even replaced all the newlines with <BR/> tags but eventhough I see the tags in my source, I don't get a line break in the output document. Any help would be greatly appreciated.
1
2315
by: Rolan | last post by:
I need to be able to remove <BR>'s that are placed in null fields (Access 97) for blank records when doing html imports. Of course, Access does not recognize the html tags and are invisible. Aside from pressing the delete key twice in each null field to remove the <BR>'s, I have found no other effective way of deleting them. The real data is too randomized to run a delete query against. Using &nbsp; is not an option either. Any assistance...
7
2737
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no tags will remain making the page safe (I have to convert the linefeeds to <BR>s because the Server.EncodeHTML does not do that it seems). The problem is that users can use a special tag when editing the top to specify an area of the tip that will...
2
2526
by: Winshent | last post by:
I have a multi line text in an admin page on my cms. I am trying to capture carriage returns as and replace them with <p></p> bfore the string gets written to the database. I have tried all the charcontrols option and chr(13) with success.. was using the following code: Dim s As String = MyTextbox.Text
1
3166
by: Winshent | last post by:
I have a multi line text in an admin page on my cms. I am trying to capture carriage returns as and replace them with <p></p> bfore the string gets written to the database. I have tried all the charcontrols option and chr(13) with success.. was using the following code: Dim s As String = MyTextbox.Text
13
18360
by: CK | last post by:
Hi all, I have a textarea control. I am putting it's value in an html email. The problem is that the new lines are being ignored. I want to take the controls value and replace any newline carriage returns, with an html <br> tag. I tried the following function but it doesn't work. Does anyone have any ideas how to accomplish this? Thanks in advance. ~ CK string getComments()
2
19569
by: xhe | last post by:
I met a very headache problem in javascript, I think this might be difference between IE and NS / Safari. I have a text area <form> <textarea name='tex1' onkeyup='displayit();'></textarea> </form> <span id="txtValue"></span> <script language='javascript'>
0
8009
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8432
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6753
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5962
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5456
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2442
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1548
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.