PDA

View Full Version : syntax for regexp??


kamarthi7
02-03-2003, 04:27 PM
hello,

can anybody please tell me, what would be the regexp for

<html><head></head>
some text here
<TABLE class="" id=Table1 borderColor=#000000 height="100%" cellSpacing=1 cellPadding=1 width="100%" align=left border=1 runat="server">
<TBODY>
<TR>
<TD class=cell>some text</TD></TR>
<TR>
<TD class=cell>some text</TD></TR>
</TBODY></TABLE>
some text here
</body></html>

I want a regExp which selects the <TABLE .....>........</TABLE>
i think match() can be used but what would be the regexp syntax.

the whole html page is in a string.

beetle
02-03-2003, 07:40 PM
The below is for if you only have one table. for multiple tables, the result syntax is a bit different.var html = '<html><head></head> some text here <TABLE class="" id=Table1 borderColor=#000000 height="100%" cellSpacing=1 cellPadding=1 width="100%" align=left border=1 runat="server"> <TBODY> <TR> <TD class=cell>some text</TD></TR> <TR> <TD class=cell>some text</TD></TR> </TBODY></TABLE> some text here </body></html> ';

var table = html.match( /\<table.+?\/table\>/i );

Tails
02-03-2003, 07:58 PM
What's regExp do? It seems that half of the tutorial sites on the net don't say half of these things, maybe because they don't know what they do. Maybe I'm not looking in the right places.

beetle
02-03-2003, 08:16 PM
In short:
Regular expressions are for string based pattern-matching. They can be used to extract matches, replace matches, split text into arrays and more.

In long:
http://zez.org/article/articleview/11/
http://www.webreference.com/js/column5/index.html
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/jscript7/html/jsjsgrpRegExpSyntax.asp
http://devedge.netscape.com/library/manuals/2000/javascript/1.5/guide/regexp.html#1010922
http://www.devarticles.com/art/1/302

Here's (http://www.peterbailey.net/scramble.htm) a silly page I made using regular expression's replacing and backreferencing capabilities.