Another way to approach this is to use
occur to select the lines you want to modify, and then apply your modification in the
M-x occur, enter the regexp that matches the lines you want to edit
- Switch to the
e to enter
M-C-% to call
query-replace-regexp, do your replacements
C-c C-c to leave
- Move back to your original window, where the modifications you made in step 4 will be made.
This does the same thing that @icarus suggests, but uses two different regexps: one to select the line, and a second to modify the selected lines. This approach requires a few more steps, but might be easier if @icarus solution requires a very complicated regexp.
You could also do variants of this using
helm-occur or other packages, but what I describe here works in regular Emacs without any additional packages.