User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Mar 2007
Posts: 5
Reputation: joequincy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joequincy's Avatar
joequincy joequincy is offline Offline
Newbie Poster

Regular Expression Headache

  #1  
Jun 18th, 2008
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.

<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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,510
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 103
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: Regular Expression Headache

  #2  
Jun 19th, 2008
If the script is embedded in the web page, it might be finding and matching itself.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Mar 2007
Posts: 5
Reputation: joequincy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joequincy's Avatar
joequincy joequincy is offline Offline
Newbie Poster

Re: Regular Expression Headache

  #3  
Jun 20th, 2008
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.
Reply With Quote  
Join Date: Sep 2005
Posts: 639
Reputation: digital-ether has a spectacular aura about digital-ether has a spectacular aura about 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: Regular Expression Headache

  #4  
Jun 21st, 2008
Originally Posted by joequincy View Post
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!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 12:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC