Page 1 of 1
Remove all <H tags
Posted: Wed Oct 08, 2003 10:07 am
by jollyjumper
Hello Everyone,
I'm trying to have all <H*>(where * is a number) tags to be removed from my html document with RegExp.
I've got this expression:
Code: Select all
var re = new RegExp("(<H1)(ї^>]*>.*?)(<\/H1>)","gi") ; html = html.replace( re, '$2' ) ;
But this keeps the last > of <H1> and only works with H1 tags, and I would like to let it work on all H tags.
I hope some one could explain me how to do this.
Greetz Jolly..
Posted: Wed Oct 08, 2003 12:18 pm
by evilMind
in php you can do:
Code: Select all
$stringToReplaceTagsIn = ereg_replace( "<(h|H)[0-9]>",'',$stringToReplaceTagsIn);
$stringToReplaceTagsIn = ereg_replace( "<\/(h|H)[0-9]>",'',$stringToReplaceTagsIn);
OR even better
Code: Select all
$stringToReplaceTagsIn = ereg_replace("<(h|H)[0-9]>",'',ereg_replace( "<\/(h|H)[0-9]>",'',$stringToReplaceTagsIn));
Posted: Wed Oct 08, 2003 2:01 pm
by jollyjumper
Hi evilMind,
Thank you very much for your reply, it helped me very much.
This is what it looks like in javascript.
Code: Select all
var text = "<H1>line1</H1>\n\n<H2>line2</H2>";
text = text.replace(/<(h|H)ї0-9]>/gi,"");
text = text.replace(/<\/(h|H)ї0-9]>/gi,"");
Again thank you.
Greetz Jolly.
Posted: Wed Oct 08, 2003 2:56 pm
by m3rajk
javascript borrows from perl. thus g = global and i = canse insensitive, and you can use the short \d
thus you can change it to /<h\d>/gi
just some notes for the future. you might wanna pick up a book on perl regular expressions or the learning perl book by oreilly press. there's a great reg exp section there (3 chapters on it) and you can learn the shorts.
Posted: Thu Oct 09, 2003 1:51 am
by jollyjumper
Hi m3rajk,
Thanks for the book reference. I'll certainly take a look at it.
Greetz Jolly.
Posted: Thu Oct 09, 2003 9:38 pm
by m3rajk
since i have learning perl, here's the isbn: 0596001320
i wish i had stock in bookpool. it's a comp.. mayby sci book specialty store on the web that keeps coming up with the lowest prices for me, and i have to include sales tax when going to them.
http://www.bookpool.com
there's 3 chapters on regular expressions, and if you are interested in perl anyway, then why not get your ref via that book?