•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,609 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,626 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 693 | Replies: 3
![]() |
I'm having one heck of a time trying to match a tag. It looks right to me (and checks out in all of the Regex Tester webapps I've tried) but does not work when I put it to use. The following is the code (with site address and name replaced with "Awesome Site") of the web page, and after that is the Javascript I'm using to try to match it. I am trying to match the Table Cell with the ID "myAlerts". Currently, it alerts null.
Of little note: I am executing this through the Greasemonkey extension for Firefox, so my method of setting the "response" variable is slightly different. In practice, it captures the entire HTML of the page, not just the contents of the Body tag. Also, the alert() is a simple replacement for where I append a DIV to the current page. For the purposes of troubleshooting, that info is irrelevant and I have already tested those components to be sure they're working properly. I'm just stating them here in anticipation that people will want to know what exactly I'm trying to accomplish.
<table cellpadding="1" cellspacing="0" width="100%"> <tbody><tr> <td id="myAlerts"> <a href="/home.php?nc=1"><b>Awesome Site Inc</b> has news.<br></a><a href="/home.php?nc=1"><b>Awesome Site Inc</b> has a comic.<br></a><a href="http://www.awesomesite.com/archive/?nc=1"><b>Awesome Site Inc</b> has a new video.<br></a><a href="/members/messaging/">You have <b>1</b> new message.</a><br><a href="/members/messaging/">You have <b>1</b> new friend request.</a><br><a href="/members/comments/index.php">You have <b>10</b> new personal comments.</a><br><a href="/members/journal/entry.php?id=2059183">You have <b>1</b> new journal comment.</a><br><a href="/members/journal/entry.php?id=2059185">You have <b>1</b> new journal comment.</a><br><a href="/members/images/image.php?id=2239675">You have <b>1</b> new image comment.</a><br><a href="/members/clearAllAlerts.php"><b>Clear all alerts.</b></a> </td> </tr> </tbody></table>
function test(){
var response=document.body.innerHTML
var regAlert=/<td id='myAlerts'>\n?(.*?)<\/td>/mi;
alert(response.match(regAlert));
}Of little note: I am executing this through the Greasemonkey extension for Firefox, so my method of setting the "response" variable is slightly different. In practice, it captures the entire HTML of the page, not just the contents of the Body tag. Also, the alert() is a simple replacement for where I append a DIV to the current page. For the purposes of troubleshooting, that info is irrelevant and I have already tested those components to be sure they're working properly. I'm just stating them here in anticipation that people will want to know what exactly I'm trying to accomplish.
not quite that simple. It's executing through the Greasemonkey extension or Firefox, and the regular expression is being matched against the HTML of an entirely separate page.
I've discovered that the failure arises with several "newline" characters in the HTML. this cannot be changed, so I guess I need to figure out how to match literally anything. A period (.) by itself matches anything except a newline, so I tried
I've discovered that the failure arises with several "newline" characters in the HTML. this cannot be changed, so I guess I need to figure out how to match literally anything. A period (.) by itself matches anything except a newline, so I tried
(.|\n)*? to attempt to match anything, but it didn't work. I'm well and truly stuck. •
•
•
•
not quite that simple. It's executing through the Greasemonkey extension or Firefox, and the regular expression is being matched against the HTML of an entirely separate page.
I've discovered that the failure arises with several "newline" characters in the HTML. this cannot be changed, so I guess I need to figure out how to match literally anything. A period (.) by itself matches anything except a newline, so I tried(.|\n)*?to attempt to match anything, but it didn't work. I'm well and truly stuck.
Very accurate discussion here:
http://simonwillison.net/2004/Sep/20/newlines/
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Nested Select Boxes in Javascript
- Next Thread: AJAX comment form



Linear Mode