Perform Search and Replace on Webpages

  • Sometimes we need functionality which can perform search and replace for us so we can directly copy paste codes.

For Example:

[mitesh@shah ~]$ cat /etc/nginx/sites-available/example.com
server {
  server_name example.com www.example.com;

  access_log /var/log/nginx/example.com.access.log rt_cache;
  error_log /var/log/nginx/example.com.error.log;

  root /var/www/example.com/htdocs;
  index  index.html index.htm;

  location / {
    try_files $uri $uri/ /index.html;
  }

  include common/locations.conf;
  include /var/www/example.com/conf/nginx/*.conf;

}
  • Instead of copy above codes and manually search and replace on vim we can directly perform search and replace on this page only.

Perform Search & Replace

  • Right click on this page
  • Click on Inspect Element
  • Click on Console
  • Copy Paste Following Code and Press Enter.
jQuery('body').html(function(index,html){
return html.replace(/example.com/g,'mitesh.com');
});

Perform Search and Replace on Webpages

  • Once you press Enter check above code
  • You can see example.com is replaced by mitesh.com just like below image.

Perform Search and Replace on Webpages



Newsletter

Get updated when I create new content.
Unsubscribe whenever. Never any spam.

Note

I'm Tama. I turn down every ad, affiliate, and sponsor request I get. I write free resources that help people. If you enjoy my content, please consider supporting what I do.

Support my work