473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

RegExp help needed!

Greetings, all...

I've got an issue that I'm trying to solve and RegExp looks to be my
only avenue.

Background: We are using a popular third party control for input into a
textarea. By default, the text is HTML but the UI does not display the
HTML tags. Because we are using this in a web-messaging scenario, the
user may choose to send their message in plain text and we want to
display that on the screen.

The third party control we're using does not have any built-in ability
to switch from their rich-text editing environment to a "plain-text"
environment.

Proposed Resolution: 1) Read the data input into the third-party
control, 2) strip all HTML markup from the data while maintaining
carriage return/line feed data, 3) Hide the third-party control and
reveal an HTML text area, and, 4) copy the reformatted text into the
text area.

Additional Feature: The user should be able to re-select HTML editing
effectively reversing this process. While any previous HTML formatting
would be lost, the cr/lf data would be preserved when switching back to
HTML.

I have played around with some regular expressions with only moderate
luck. None of the freely available patters on RegExLib.com seem to do
what is needed.

Here's the current pattern I'm working with: <[^>]+?>
This pattern strips all the HTML, but does not preserve the cr/lf data.

I would really appreciate any assistance that can be offered. If you
know of a pattern that would reliably do the conversion from HTML to
plain-text, and the companion that would do the plain-text to HTML, I
would be very grateful!

Thanks in advance,
Ric Castagna

Oct 13 '05 #1
1 1243
wrote on 13 okt 2005 in comp.lang.javascript:
2) strip all HTML markup from the data while maintaining
carriage return/line feed data


http://www.google.com/search?q=strip.html%20regex
and
http://groups.google.com/groups?q=strip.html+regex
will give you ample examples of the needed regex

However what crlf do you want to safe?
the <br> and the <hr> or also the <div>?

you could very well detect them first and reassign them first,
and restort the <br> at the end:
================================================== ===
t = t.replace(/(<br>)|(<hr>)|(</div>)/gi, "*\\*")

t = t.replace(/[do your stripping]/gi, "")

t = t.replace(/\*\\\\\*/g, "<br>")
================================================== ===
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 13 '05 #2

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

Similar topics

2
by: Patryk Konieczka | last post by:
Hello Here's the thing I have a database edited by some company workers editing descriptions of books in the sotre , unfortunately these workers do not have the habit of inserting a space...
10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
4
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as...
2
by: Tamas Nyilanszky | last post by:
hi, i need to filter (e.g.) the number 149, 1307 and 3100 from a line like this one: <td id=l2 title=149>1307/3100</td> so i will be able to split that string with reg.split() and receive...
26
by: Matt Kruse | last post by:
Are there any current browsers that have Javascript support, but not RegExp support? For example, cell phone browsers, blackberrys, or other "minimal" browsers? I know that someone using Netscape...
27
by: SQL Learner | last post by:
Hi all, I have an Access db with two large tables - 3,100,000 (tblA) and 7,000 (tblB) records. I created a select query using Inner Join by partial matching two fields (X from tblA and Y from...
3
by: Paddy | last post by:
Lets say i have a generator running that generates successive characters of a 'string' characters then I would have to 'freeze' the generator and pass the characters so far to re.search. It is...
4
by: Matt | last post by:
Hello all, I have just discovered (the long way) that using a RegExp object with the 'global' flag set produces inconsistent results when its test() method is executed. I realize that 'global'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.