#1
  1. No Profile Picture
    Dim Brendan as Noob
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    479
    Rep Power
    506

    Javascript Regex


    <table width="100%" cellspacing="0"><tr> <td style="width:25%;" valign="bottom">
    <table style="margin-left:auto;margin-right:auto;">
    <tr>
    <td style="text-align:center;">
    <img src="../images/items/individual/largos/misc/head-goggles.png" alt="" onmouseover="showItemTip('237522');" onmouseout="hidetip();" style="cursorointer;" />
    </td>
    </tr>

    <tr>
    <td>
    <input style="border:0px;" type="radio" onclick="window.location='backpack.php?equip=237522';"> Equip<br /><input style="border:0px;" type="radio" onclick="confirmDrop('237522');"> Drop<br /> <input style="border:0px;" type="radio" onclick="confirmDestroy('237522');"> Destroy
    </td>
    </tr>
    </table>

    </td>
    <td style="width:25%;" valign="bottom">
    <table style="margin-left:auto;margin-right:auto;">
    <tr>
    <td style="text-align:center;">
    <img src="../images/items/individual/largos/jumpsuit/torso.png" alt="" onmouseover="showItemTip('237523');" onmouseout="hidetip();" style="cursorointer;" />
    </td>
    </tr>
    <tr>

    <td>
    <input style="border:0px;" type="radio" onclick="window.location='backpack.php?equip=237523';"> Equip<br /><input style="border:0px;" type="radio" onclick="confirmDrop('237523');"> Drop<br /> <input style="border:0px;" type="radio" onclick="confirmDestroy('237523');"> Destroy
    </td>
    </tr>
    </table>
    </td>

    <td style="width:25%;" valign="bottom">
    <table style="margin-left:auto;margin-right:auto;">
    <tr>
    <td style="text-align:center;">
    <img src="../images/items/halloween/halloween-jumppack.png" alt="" onmouseover="showItemTip('241156');" onmouseout="hidetip();" style="cursorointer;" />
    </td>
    </tr>
    <tr>
    <td>

    <input style="border:0px;" type="radio" onclick="confirmUse('241156','Use Device');"> Use Device<br /> <input style="border:0px;" type="radio" onclick="confirmDestroy('241156');"> Destroy
    </td>
    </tr>
    </table>
    </td>
    <td width="100%"></td></tr></table>
    Above is the html I am looking through. What I want is each number after ?equip=

    The following is the regex code that I have tried in Javascript:

    Code:
    var totalreg = new RegExp(/(?!\?equip\=)(\d+)(?=';)/g);
    var total = totalreg.exec(content);
    if (total != null)
    	{
    	alert(total.join("\n"));
    	}
    else
    	{
    	alert("No match.");
    	}
    The code returns "66 \n 66" and 66 does appear elsewhere in the page but nothing even comes close to the ?equip= regex so I'm at a loss.

    Any help is appreciated, thank you.
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,128
    Rep Power
    4304
    Try this:
    Code:
    var totalreg = /\?equip=\d+/g;
    var total = content.match(totalreg);
    if (total != null)
    	{
    	alert(total.join("\n").replace(/\?equip=/g,''));
    	}
    else
    	{
    	alert("No match.");
    	}

    Comments on this post

    • Brendan.C agrees : This man right here, he's a good man. You respect him.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo