You might be able to write a program that would do it but it probably would be faster, and certainly easier although I'm sure more boring, to do it manually. Also keep in mind that spaces are not recommended in file names. They don't always work, and if nothing else can fill the page header with lots of %20s.
I suppose you could use Find and Replace (Ctrl+F) with RegEx (regular expressions). But I'm no expert with RegEx.
Finding arbitrary text within tags (e.g., the filename (without extension) in an img tag) could be done with Regex. The challenge would be to then copy whatever is found and then find a place before the end of the tag and then paste it there.
DW's Regex is not quite Unix standard. DW also lacks the other tools you'd need like piping of commands and maybe even grep.