string.replace not working
Hello:
A new repository of US caselaw[1] has recently been released, and I'm
trying to make it a little more useful.
At this URL (which happens to be Brown v. Bd. of Ed.),
http://bulk.resource.org/courts.gov/c/US/347/347.US.483.html, I'm
trying to convert data which looks so, " 123 U.S. 456", into a link,
so, "<a href=\"../123/123.US.456.html\"> 123 U.S. 456</a>".
This text.replace works on a literal string: "blah blah 123 U.S. 456
blah blah 789 U.S. 123".replace(/\s+(\d+)\s+U\.S\.\s+(\d+)/g, " <a
href=\"../$1/$1.US.$2.html\">$&</a>"); replacing both
citations with the appropriate link.
but I cannot get it to work on the document. Here's the script:
var b = document.body.innerHTML;
b.replace(/\s+(\d+)\s+U\.S\.\s+(\d+)/g, " <a
href=\"../$1/$1.US.$2.html\">$&</a>");
b = "<!--modified content-->" + b;
document.body.innerHTML = b;
I stuck the 'modified content' comment in there as a sanity check, and
it appears in the modified source. I tried wrapping the last line
inside a window.addEventListener load statement, but it made no
difference. I have a feeling I'm missing something incredibly
obvious! I re-read the common pitfalls chapter, but saw nothing
there. Any insights would be much appreciated.
pw
[1] See http://bulk.resource.org/courts.gov/
Reply to: