...

View Full Version : Assistance with regular expressions



scrupul0us
01-27-2009, 02:18 AM
on page load, how would i check the entire body for a string and if that string was found, use alert() to notify the user?

thanks

BubikolRamios
01-27-2009, 03:25 AM
See no reason why woud you do do that, as the stuff comes from server you know it before it loads. Use server side scripting.


Otherwise:

match function
and document.innerHTML

this wont work on ie6 coz there is a size limit for innerHTML, don't know how would you do it there, unless parsing whole doc via DOM

scrupul0us
01-27-2009, 04:12 AM
ill give it a go... im trying to throw a small grease monkey script together to alert me whenever something is within the content of a page im on

thanks

Philip M
01-27-2009, 08:28 AM
Try this:-



<script type="text/javascript" >

var str2find = "P~hi~li~p"
// Note: str2find must be munged initially with ~ characters as otherwise the string will always be found!
str2find = str2find.replace(/~/g,""); // unmunge

window.onload=function(){
var str = document.getElementsByTagName('html')[0].innerHTML;
var a = str.indexOf(str2find);
if (a >= 0) {
alert ("The HTML contains the string " + str2find);
}
else {
alert ("Sorry - this sequence of characters was not found.");
}
}
</script>


"In the beginner's mind there are many possibilities, but in the expert's mind there are few. Shunryu Suzuki (Japanese Zen priest, ?-1971)

scrupul0us
01-27-2009, 12:28 PM
thanks phil.. it appears as if the window.onload isntfiring:



var str2find = "~secret~"
str2find = str2find.replace(/~/g,""); // unmunge

window.onload=function()
{
alert("MADE IT");
var str = document.getElementsByTagName('body')[0].innerHTML;
var a = str.indexOf(str2find);
if (a >= 0)
{
alert ("The HTML contains the string " + str2find);
}
else
{
alert ("Sorry - this sequence of characters was not found.");
}
}


I never get the alert "MADE IT"

Philip M
01-27-2009, 12:41 PM
thanks phil.. it appears as if the window.onload isntfiring:



var str2find = "~secret~"
str2find = str2find.replace(/~/g,""); // unmunge

window.onload=function()
{
alert("MADE IT");
var str = document.getElementsByTagName('body')[0].innerHTML;
var a = str.indexOf(str2find);
if (a >= 0)
{
alert ("The HTML contains the string " + str2find);
}
else
{
alert ("Sorry - this sequence of characters was not found.");
}
}


I never get the alert "MADE IT"

No idea why. Of course, you cannot inject the script into some external web page in another domain. The best you can do is to View Source, and then capture the code and then search for the character sequence in question. You could do that with Notepad.


var str2find = "~secret~" is not properly munged as the sequence secret necessarily appears on the page - in this line. You must do something like
var str2find = "se~cr~et";that is, place the tildes within the string.

scrupul0us
01-27-2009, 01:08 PM
@phil: its a greasemonkey script for firefox... its not really injected anywhere as its run on my local machine... the string im looking for is just one word so doing the view source etc... doesnt really apply

never-the-less the issue seems to be that the onload isnt firing

@cranford: im reviewing



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum