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 374,197 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 3,545 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: 660 | Replies: 3 | Solved
Reply
Join Date: Apr 2008
Posts: 2
Reputation: blaater is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
blaater blaater is offline Offline
Newbie Poster

javascript regular expression problem

  #1  
Apr 23rd, 2008
Hello,

Currently I'm working on a funtcion which has to eval() some events from a string i'm injecting into the dom. The problem is that i've tested my regular expression on http://www.regular-expressions.info/...ptexample.html and every time it works perfect. Only when I implement it in my website it doesn't work. The string I'm using is :
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus sollicitudin dolor et eros. Aenean diam ipsum, rhoncus sed, laoreet et, vulputate non, ligula. Nulla vehicula, augue vel pharetra hendrerit, mauris lorem cursus nunc, at ullamcorper eros libero </p><p><p class="swfObject left" id="flash95_263671"></p><script type="text/javascript">var so95_263671 = new SWFObject("/file/get-swf/iFileId/95", "flash95_263671", "250", "500", "8", "#ffffff");so95_263671.addParam("wmode", "opaque");window.addEvent('load', function () {so95_263671.write("flash95_263671");});</script></p> <p>eget ipsum. Donec et ante eu mauris facilisis vestibulum. Morbi dolor lectus, molestie ut, bibendum non, interdum dignissim, dolor. Quisque at arcu.</p>

The function I'm using is:

	function evaluateBlock(sString) {
		var sRegexp = "(so[0-9]+_[0-9]+.write\(\".*\"\);)";
		var regex = new RegExp(sRegexp);
		console.log(sString);
		var match = regex.exec(sString);
		if (match == null) {
			console.log("No match");
		} else {
			var string = "match at position " + match.index + ":\n";
			string = string + "string matched: " + match[0] + "\n";
			if (match.length > 0) {
				for (var i = 1; i < match.length; i++) {
					//eval(match[i]);
					console.log(match[i]);
				}
			}
			console.log(string);
		}
	}

Does anybody know the solutions for my problem?
Thanks in advance!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 1,907
Reputation: peter_budo has a spectacular aura about peter_budo has a spectacular aura about peter_budo has a spectacular aura about 
Rep Power: 9
Solved Threads: 216
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Posting Virtuoso

Re: javascript regular expression problem

  #2  
Apr 24th, 2008
JavaScript is not Java or JSP ! ! ! Post moved to JavaScript section...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Mar 2008
Posts: 25
Reputation: blater is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
blater's Avatar
blater blater is offline Offline
Light Poster

Re: javascript regular expression problem

  #3  
Apr 24th, 2008
The following doesn't work on the website you quoted, but seems to work on firefox (with the briefest of testing )...

   var sRegexp = "so[0-9]+_[0-9]+\.write\\(\'.*\'\\)\;";

I've added escaping for the "." before "write", the single quotes, the semicolon, and the parenthesis.
Reply With Quote  
Join Date: Apr 2008
Posts: 2
Reputation: blaater is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
blaater blaater is offline Offline
Newbie Poster

Re: javascript regular expression problem

  #4  
Apr 25th, 2008
Thanks a lot, you really helped me out!

The code is still not working because the javascript isn't recognised by the browser, have to eval() all the code within the <script> tags, except for the event, I'll figure it out myself.

Thanks!
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

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

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