codegoboom
03-13-2005, 05:11 AM
I tried hiding 'special characters' (such as '[') with "\", or "\\", or "\\\\", for the 'line' parameter, but get: [Error: Expected ')' in regular expression]. Is that the wrong escape method, or...?
<body onload="sPrompt('HoHoHo')">
<script type="text/javascript">
// Periodic Strings (http://acm.uva.es/p/v4/455.html) play...
function periodic(line){
var i = 0;
do{++i} while(!RegExp("^(" + line.substr(0, i) + ")+$").test(line));
return i;}
// test
function sPrompt(line){
if(line = prompt(line + " => " + periodic(line), ""))
sPrompt(line);}
</script>
</body>
<body onload="sPrompt('HoHoHo')">
<script type="text/javascript">
// Periodic Strings (http://acm.uva.es/p/v4/455.html) play...
function periodic(line){
var i = 0;
do{++i} while(!RegExp("^(" + line.substr(0, i) + ")+$").test(line));
return i;}
// test
function sPrompt(line){
if(line = prompt(line + " => " + periodic(line), ""))
sPrompt(line);}
</script>
</body>