Hello,
I'm new with Regular Expression. I've been trying to find the right
regular expression to accomplish what I'm trying to do... but without
much success so far.
I understand there are a bunch of "special characters" used for
creating the regular expression. http://www.devguru.com/technologies/...ript/11284.asp
I'm trying to globally replace all the HTML anchor from the string,
because I'm grabbing the string from innerHTML of an element.
So if I have a table, with bunch of cell (i.e TD) with <A {some
text}>{some more text}</A>, how can I use the string.replace function
with the appropriate regular expression, subsitute the <a, >, and </a>
with blank?
Thank in advance for the help
Kelvin 4 1040
kelvlam wrote:
Hello,
I'm new with Regular Expression. I've been trying to find the right
regular expression to accomplish what I'm trying to do... but without
much success so far.
I understand there are a bunch of "special characters" used for
creating the regular expression. http://www.devguru.com/technologies/...ript/11284.asp
I'm trying to globally replace all the HTML anchor from the string,
because I'm grabbing the string from innerHTML of an element.
So if I have a table, with bunch of cell (i.e TD) with <A {some
text}>{some more text}</A>, how can I use the string.replace function
with the appropriate regular expression, subsitute the <a, >, and </a>
with blank?
Thank in advance for the help
Kelvin
I found my own solution finally!
var printContent = new String(objSource.innerHTML);
// remove all the <abegin tag
printContent = printContent.replace(/<a[^>]*>/g,"");
// remove all the </aend tag
printContent = printContent.replace(/<\/a>/g,"");
You can combine these two statements, if you like, by using a ? with
the "/" character, like this:
replace(/<\/?a[^>]*>/g,"")
Stan Scott
New York City
I'm trying to globally replace all the HTML anchor from the string,
because I'm grabbing the string from innerHTML of an element.
var printContent = new String(objSource.innerHTML);
// remove all the <abegin tag
printContent = printContent.replace(/<a[^>]*>/g,"");
// remove all the </aend tag
printContent = printContent.replace(/<\/a>/g,"");
kelvlam said the following on 9/13/2006 6:34 PM:
kelvlam wrote:
>Hello,
I'm new with Regular Expression. I've been trying to find the right regular expression to accomplish what I'm trying to do... but without much success so far.
I understand there are a bunch of "special characters" used for creating the regular expression. http://www.devguru.com/technologies/...ript/11284.asp
I'm trying to globally replace all the HTML anchor from the string, because I'm grabbing the string from innerHTML of an element.
So if I have a table, with bunch of cell (i.e TD) with <A {some text}>{some more text}</A>, how can I use the string.replace function with the appropriate regular expression, subsitute the <a, >, and </a> with blank?
Thank in advance for the help
Kelvin
I found my own solution finally!
var printContent = new String(objSource.innerHTML);
// remove all the <abegin tag
printContent = printContent.replace(/<a[^>]*>/g,"");
Be aware though that if the A anchor has any string in it that contains
then you wont strip the entire A element. onmouseover="if(a>b)" or
similar then it will stop at that first >
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Randy Webb wrote:
kelvlam said the following on 9/13/2006 6:34 PM:
kelvlam wrote:
Hello,
I'm new with Regular Expression. I've been trying to find the right
regular expression to accomplish what I'm trying to do... but without
much success so far.
I understand there are a bunch of "special characters" used for
creating the regular expression. http://www.devguru.com/technologies/...ript/11284.asp
I'm trying to globally replace all the HTML anchor from the string,
because I'm grabbing the string from innerHTML of an element.
So if I have a table, with bunch of cell (i.e TD) with <A {some
text}>{some more text}</A>, how can I use the string.replace function
with the appropriate regular expression, subsitute the <a, >, and </a>
with blank?
Thank in advance for the help
Kelvin
I found my own solution finally!
var printContent = new String(objSource.innerHTML);
// remove all the <abegin tag
printContent = printContent.replace(/<a[^>]*>/g,"");
Be aware though that if the A anchor has any string in it that contains
then you wont strip the entire A element. onmouseover="if(a>b)" or
similar then it will stop at that first >
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Thanks Stan, I also realized because I'm using XSLT transformation,
adding the "i" flag would make it work for both Firefox and IE. Now I
can do it all in 1 line Javascript instead of 2.
Randy pointed out a a good caveat to watch out for. Fortunately any
javascript event or HTML attribute of the <Atag doesn't contain the
">" in my scenario. Or else...
Much appreciate the responses.
Kelvin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:...
|
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....
|
by: Chris Croughton |
last post by:
I'm trying to use the EXSLT regexp package from
http://www.exslt.org/regexp/functions/match/index.html
(specifically the match function) with the libxml xltproc (which
supports EXSLT), but...
|
by: ric.castagna |
last post by:
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...
|
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...
| |
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...
|
by: Matt |
last post by:
Premise: Inserting data into a database form a <textarea> and
displaying this data through an HTML page.
When inserting data into a database via a text area and then displaying
this data any...
|
by: Csaba Gabor |
last post by:
I need to come up with a function
function regExpPos (text, re, parenNum) { ... }
that will return the position within text of RegExp.$parenNum if there
is a match, and -1 otherwise.
For...
|
by: VUNETdotUS |
last post by:
Hi, I am working with this regexp to extract address: city, state, and
zip. This version kinda works but it extracts one element of an array
instead of three and keeps my "city" too long, including...
|
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'...
|
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...
| |
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |