What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » [RESOLVED] JavaScript: Remove <table>blah</table>

Pages: (2): « First [ 1 ] 2 » Last »
[RESOLVED] JavaScript: Remove <table>blah</table>
Author: Message:
macgyver08
Junior Member
**

Avatar
Hakuna matata!

Posts: 23
35 / Male / Flag
Joined: Feb 2007
O.P. [RESOLVED] JavaScript: Remove <table>blah</table>
I've tried...
code:
string.replace(/<table([^%]+)</table>/ig,"");
...but it doesn't seem to be working.

This post was edited on 01-30-2010 at 12:05 AM by macgyver08.
01-29-2010 09:32 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: JavaScript: Remove <table>blah</table>
Are you trying to replace everything including the <table></table>?
01-29-2010 09:37 PM
Profile E-Mail PM Find Quote Report
macgyver08
Junior Member
**

Avatar
Hakuna matata!

Posts: 23
35 / Male / Flag
Joined: Feb 2007
O.P. RE: RE: JavaScript: Remove <table>blah</table>
quote:
Originally posted by matty
Are you trying to replace everything including the <table></table>?

Yes, the table tags, and everything they contain.
01-29-2010 09:39 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: JavaScript: Remove <table>blah</table>
js code:
// IGNORE -> html = html.replace(/\<table\>.+?\<\/table\>/gi, "");
html = html.replace(/\<table.+?table\>/gi, "");

Should do it.

EDIT:
Changed it to allow for attributes in the table tag such as styles, class, id etc.

This post was edited on 01-29-2010 at 09:49 PM by Spunky.
<Eljay> "Problems encountered: shit blew up" :zippy:
01-29-2010 09:45 PM
Profile PM Find Quote Report
macgyver08
Junior Member
**

Avatar
Hakuna matata!

Posts: 23
35 / Male / Flag
Joined: Feb 2007
O.P. RE: RE: JavaScript: Remove <table>blah</table>
quote:
Originally posted by Spunky
js code:
// IGNORE -> html = html.replace(/\<table\>.+?\<\/table\>/gi, "");
html = html.replace(/\<table.+?table\>/gi, "");

Should do it.

EDIT:
Changed it to allow for attributes in the table tag such as styles, class, id etc.
Doesn't appear to be working *-)

EDIT: I didn't see your edit before i said it didn't work. Let me try your new one.

This post was edited on 01-29-2010 at 09:59 PM by macgyver08.
01-29-2010 09:59 PM
Profile E-Mail PM Find Quote Report
macgyver08
Junior Member
**

Avatar
Hakuna matata!

Posts: 23
35 / Male / Flag
Joined: Feb 2007
O.P. RE: JavaScript: Remove <table>blah</table>
New one isn't working either. I don't know if it's your code,or my code that I've  pasted it to though.

I replaced the code with one that removes square brackets and that works, so...it seems like it's your code. Not to insult though, I really appreciate the help, it's just not working.

This post was edited on 01-29-2010 at 10:04 PM by macgyver08.
01-29-2010 10:03 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: JavaScript: Remove <table>blah</table>
Yes, it does work. Maybe there is some strange character in the html?

[Image: attachment.php?pid=986406]

EDIT: Try adding the m modifier to make it run over multiple lines... My test was on a single line basis

.png File Attachment: Capture.png (11.67 KB)
This file has been downloaded 1441 time(s).

This post was edited on 01-29-2010 at 10:14 PM by Spunky.
<Eljay> "Problems encountered: shit blew up" :zippy:
01-29-2010 10:13 PM
Profile PM Find Quote Report
macgyver08
Junior Member
**

Avatar
Hakuna matata!

Posts: 23
35 / Male / Flag
Joined: Feb 2007
O.P. RE: JavaScript: Remove <table>blah</table>
Well...it's not working with my code for some reason. I don't know why. What strange character in the HTML could stop it from working?

Also, I'm fairly new to JavaScript, so it's quite likely it's something I've done (or haven't done). Everything else is working though. I just need this one line finished and I think it'll be finished lol
01-29-2010 10:18 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: JavaScript: Remove <table>blah</table>
quote:
Originally posted by macgyver08
\<table.+?table\>/gi

I dunno, experiencing a problem with it too now with a more complicated table
<Eljay> "Problems encountered: shit blew up" :zippy:
01-29-2010 10:29 PM
Profile PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: JavaScript: Remove <table>blah</table>
Line breaks are casuing it to break and I can't get the m modifier to work so we can add an extra replace.

js code:
html = html.replace(/\n/gi, "").replace(/\<table.+?table\>/gi, "");

If you wanted to, you could replace the \n with a unique string so it can be put back together again...

js code:
html = html.replace(/\n/gi, "this-used-to-be-a-line-break").replace(/\<table.+?table\>/gi, "");
html = html.replace(/this-used-to-be-a-line-break/gi, "\n");
// This is just so the source formatting looks good when viewed,
// rather than all being on one line

This post was edited on 01-29-2010 at 10:41 PM by Spunky.
<Eljay> "Problems encountered: shit blew up" :zippy:
01-29-2010 10:40 PM
Profile PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On