This looks perfect.
Please note that Athanasius's s/&#\d(?!\d);?//g solution also replaces  (including the semicolon at the end) with the empty string (see first code example) and does not replace & (no trailing semicolon) (update: or &# or & either, with or without trailing semicolon).
This does not square with my understanding of your OP, which led me to think that '&;' '&#;' '' should all be reduced to ';' (a lone semicolon). (tybalt89's solution exactly implements my understanding of the OPed requirements.)
... replace the string without opening the file ...
I have to say that I share Laurent_R's lack of understanding of what you mean by "without opening the file". How do you imagine that any operation, even simply reading the file, can be performed (update: on the contents of the file) without first opening the file? (Update: Although you could, of course, entirely delete the file and its contents without ever opening it.) Do you mean that you want code that is written without any explicit open function call? If so, what is the purpose of this requirement? Is this really just some oddball homework assignment?
Give a man a fish: <%-{-{-{-<
In reply to Re^4: Need a regex to replace incomplete html entities
by AnomalousMonk
in thread Need a regex to replace incomplete html entities
by Chris Daniel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |