The code is way messed up javascript. Even if no eval where involved neither the re nor the search will do what's expected/desired.
This re:
Means the beginning of the string followed by a space or a letter A, B, or C, or by a | symbol. The gi switch means that the search is global (g) -I'm not sure if that means the beginning of each line or only the very beginning of the string. Experiment is warranted. Or does it matter? You said word, it doesn't check the beginning of each word. The case insensitive (i) means just that - I thought you were only interested in upper case letters.
A better regular expression would be:
That would check for a word boundary followed by a capital letter A, B, or C. The g switch would now check the entire string.
But if you use eval, \b means the lower case letter b, so you would have to double escape it:
The search expression:
Code:
str.search(re) == -1
will return true if the re is not found in the string, the opposite of what you say you want. I would scrap it altogether and use instead the test method:
which returns true if the re is in the string, false if it's not.
So, I don't know about reloading of the page or about the EXTRACT or (upper case) EVAL, how any of that works in iMacros. But in javascript this works:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
onload = function(){eval("var re = /\\b[A-C]/g; var str = document.body.innerHTML; alert(re.test(str));");};
</script>
</head>
<body>
Will Alert True Because of the A's and B's at the beginning of words
</body>
</html>
And this:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
onload = function(){eval("var re = /\\b[A-C]/g; var str = document.body.innerHTML; alert(re.test(str));");};
</script>
</head>
<body>
Will alert false because of no upper cAse a's or b's at the beginning of words
</body>
</html>
If you want to play with it, be aware that comments in the body count as text for the function.
Or put another way:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
onload = function(){eval("var re = /\\b[A-C]/g; var str = document.body.innerHTML; if(re.test(str)){location.reload();}");};
var texts = [
"Will be fAlse beCAuse there's no upper cAse a's, b's, or c's at the beginning of words",
"Will Be True Because of the A's and B's at the beginning of words",
"Will be true even though the only 'keyword' is in a span after a linebreak.\n<br><span style='color: red;'>B</span>",
"another one that will be false"
];
texts.sort(function(){return 0.5 - Math.random();});
</script>
</head>
<body>
<script type="text/javascript">
document.write(texts[0]);
</script>
</body>
</html>
Bookmarks