Friday, February 17, 2012

Javascript regex replace weird behavior


I'm developing a js to dig up Bible references on Portuguese web pages, and link them to a youversion.com url.



This is one of those pages: http://www.adventistas.org.pt/Evangelismo/Web/Img/Downloads/Trimensario/2012/1t/online/licao7.htm



This is the script: http://www.adventistas.org.pt/Evangelismo/Web/Img/Downloads/Trimensario/2012/1t/online/bibleref.js



It pretty much works, but it acts kinda funny, and can't find out why.



Sometimes it outputs empty links with correct bible references, and then outputs the real link, with a wrong reference.



Eg:




<a target="_blank" href="http://www.youversion.com/bible/verse/arc/gen/2/1-3" class="passagem"></a>
<a target="_blank" href="http://www.youversion.com/bible/verse/arc/gen/2/1-3" class="passagem"></a>
<a target="_blank" href="http://www.youversion.com/bible/verse/arc/gen/2/1-3" class="passagem"></a>
<a target="_blank" href="http://www.youversion.com/bible/verse/arc/gen/2/1-3" class="passagem"></a>
<a target="_blank" href="http://www.youversion.com/bible/verse/arc/gen/2/1" class="passagem">GĂ©nesis 2:1</a>-3;



Sometimes it works perfectly. Can anyone help track down the culprit?



Thanks!

No comments:

Post a Comment