Due to the limitations imposed by the regular expressions, it's not possible to do what you're asking for using a regex in a single run. But you can do it partially:
(?<=src=")(.*?)\s+(.*?)(?=\.)
You've mentioned that you're making use of a text editor to run this regex. If you're using something like Notepad++, you should be able to click the replace button multiple times until you reach the expected result, replacing your text by $1_$2. It shouldn't be too much of a problem if your image file paths doesn't have too much whitespaces in between them.
Explanation of the regex:
- (?<=src=")- This is a positive look behind, used to match only strings that are preceeded by this pattern. I'm using the- srcproperty as a reference instead of the- <img>tag.
- (.*?)\s+(.*?)- This matches any whitespaces between two blocks of text. I've used lazy quantifiers to avoid wrong matches. I've also wrapped these blocks on capturing groups to use them on substitution.
- (?=\.)- This is a positive lookahead. The text will match until it reaches a dot character, literally. That is, assuming that there won't be any other dots on the line. You should change this assertion if that's not the case.
Demonstration: regex101.com
I've also tested this regex on Notepad++, hitting the substitution button multiple times. The expected results were achieved.