This is a log for a building of apartments. Each apartment/unit number is a 3 or 4 digits. When a log entry is entered, I use the code to link the 3 or 4 digit number to an informational page about the apt. that is generated by resident-info.pl.
It works wee, except sometimes people update the log and enter a date in the log itself. When that happens the year is then tagged as a unit number when it shouldn't be.
Also, there have been times when someone has included HTML tags in the log entry, and perhaps a URL that includes a number that is not a unit number. The code above then isolates part of that HTML and tries to place a new URL with bold tags around the number in the manually entered HTML. That screws things up.
I hope that's clear.