Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Location
    Northbrook, IL
    Posts
    394
    Thanks
    8
    Thanked 6 Times in 6 Posts

    Unhappy regular expression help please....

    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:
    Code:
    <!secContent>
    <form id="contactsDetails" action="" method="post">
        <fieldset id="details">
    ...
    (this is plain HTML + echoed HTML from PHP thats requested through AJAX)

    target 2:
    Code:
    <!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.

    Code:
    <!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:
    Code:
    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
    Last edited by Leeoniya; 06-06-2007 at 11:56 PM.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,620
    Thanks
    0
    Thanked 645 Times in 635 Posts
    That will match the first <! and the last > in your page. To just select the specific tag you will want

    (/(<!.*?>)/)
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder
    Join Date
    Apr 2006
    Location
    Northbrook, IL
    Posts
    394
    Thanks
    8
    Thanked 6 Times in 6 Posts

    Thumbs up

    that did it, also allowed me to remove the \n.

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •