Best way to search and replace these regexes?

You can use rake posts:remap to do this, but I think you need to specify "regex" as 3rd parameter, otherwise the other parameters are treated as strings.

Another option is to use the rails console and use Ruby to do the update:

imported_posts = Post.where("id < your_last_imported_post_id")
imported_posts.find_each do |post|
  raw = post.raw.gsub(/<your magic regex here>/, "<your replacement here>")
  post.update_column(:raw, raw)
end

This way, you can also perform a dry run first, output the possible matches and accompanying replacements and see whether everything works as intended. Multiple replacements in one run are of course also possible then.