...

View Full Version : regular expression help please....



Leeoniya
06-06-2007, 11:49 PM
i'm using split() and need to match all instances of, and everything between and including <! and >

i need the actual delimiters, so i think the parentheses in the following regexp are necessary to return the delimiter matches to the array.

i am currently using split(/(<!.*>)/) this returns an empty string into the array[0] which i shift() out; and an empty string into the last array element ehich i ignore

target 1:

<!secContent>
<form id="contactsDetails" action="" method="post">
<fieldset id="details">
...
(this is plain HTML + echoed HTML from PHP thats requested through AJAX)

target 2:

<!contacts_footer><td colspan='5'>Showing 1-3 of 6 records.<br /><a href=\"#\" onclick=\"filtSort('contacts', '0')\">Page 1</a><br /><a href=\"#\" onclick=\"filtSort('contacts', '3')\">Page 2</a><br /></td><!contacts_data><tr id='6'><td>Anetsberger Brothers, Inc.</td><td>Tom</td><td>Theis</td><td>Lake Bluff</td><td>IL</td></tr><tr id='3'><td>Dan-Marc Enterprises</td><td>Dennis</td><td>Helma</td><td>Deerfield</td><td>IL</td></tr><tr id='4'><td>GTR Video Productions</td><td>Gerald</td><td>Rogers</td><td>Highland Park</td><td>IL</td></tr>
(this is returned AJAX xmlhttp.responseText to a request that is entirely echoed HTML from PHP)

for the second target, the regex returns an empty string to array[0] (which is fine)...but it returns everything else to array[1] and an empty string to array[2]

it should have matched <!contacts_footer>, and <!contacts_data> in the second target.

things improve when i echo a "\n" after each delimiter.


<!contacts_footer>\n<td colspan='5'>Showing 1-3 of 6 records.<br /><a href=\"#\" onclick=\"filtSort('contacts', '0')\">Page 1</a><br /><a href=\"#\" onclick=\"filtSort('contacts', '3')\">Page 2</a><br /></td><!contacts_data>\n<tr id='6'><td>Anetsberger Brothers, Inc.</td><td>Tom</td><td>Theis</td><td>Lake Bluff</td><td>IL</td></tr><tr id='3'><td>Dan-Marc Enterprises</td><td>Dennis</td><td>Helma</td><td>Deerfield</td><td>IL</td></tr><tr id='4'><td>GTR Video Productions</td><td>Gerald</td><td>Rogers</td><td>Highland Park</td><td>IL</td></tr>

so it does separate the delimiters correctly, but for some reason it leaves the "\n" and puts them into the next array element with next token (up to the next delimiter. since this is being returned to a tbody and tfoot of a table, it doesnt want that \n in the front, so i get errors, and no table update.

on the frontend i get this error:

tblTbody.childNodes[i].setAttribute is not a function
because it thinks childnode 0 is the "\n" that comes before the <td>. (not sure why it ends up being a literal string in the HTML code)

:(
help please.
Leon

felgall
06-06-2007, 11:54 PM
That will match the first <! and the last > in your page. To just select the specific tag you will want

(/(<!.*?>)/)

Leeoniya
06-07-2007, 12:01 AM
that did it, also allowed me to remove the \n.

thanks a ton, i was ready to pull out hair.
Leon



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum