Best way to search and replace within serialized database strings?

It seems WP-CLI is indeed one of the easiest ways to search/replace serialized strings, e.g. for replacing any unwanted instances of staging links:

wp search-replace --all-tables

The above command will search the entire WordPress database for the first string, and replace all instances with the second string provided. If you want to test it first, try this:

wp search-replace --all-tables --dry-run

You can also target certain sites in a Multisite network using this approach:

wp search-replace --network --precise --all-tables

On one particular website I was trying to optimize, Better Search Replace plugin had failed to replace all the serialized strings caused by the page builder plugin (WP Bakery). I had tried to replace the full URL strings exactly like above, and also the domain names without the https:// prefix in my strings… but it failed to cleanup the broken links around the website.

I tried again with WP-CLI and it also failed to cleanup the website until I dropped the https:// prefix from my strings, and then it worked perfectly. I discovered wp_options and wp_postmeta tables were also affected by this second attempt, when initially only wp_posts table was affected.

This probably depends on how certain plugins and themes store and retrieve their data… it doesn’t make sense to me since editing a page in WP Bakery displays the full absolute URL in the editor, but for some reason the other serialized data in the other (non-wp_posts) tables had to be cleaned up also, to fix all broken links.

P.S. I’m not a fan of answering WPSE questions just to say “use WP-CLI” without providing actual code snippets, so I will update this answer later if I find other methods.