'Change the current URL in Chrome using a regular expression or similar

When a deprecated URL is entered in Chrome it should be changed to an updated URL based on a regular expression or similar.

I would like to do the following

  1. Input a rule to the system that changes "olddomain.com" to "newdomain.com"
  2. Enter a URL like "olddomain.com/stuff" in Chrome
  3. Chrome changes the url to "newdomain.com/stuff" and loads the page
  4. Repeat 2 and 3

But I don't know if it is even possible. Any hint on where to look?



Solution 1:[1]

Modified from the related answer

chrome.tabs.getSelected(null, function (tab){
  var tabUrl = tab.url;
  // First parameter is the regex, second one is the replacement.
  tabUrl = tabUrl.replace(/([abcde])+/g, "$1");
  chrome.tabs.update(tab.id, {url: tabUrl});
});

Note that I don't really know much about Chrome development, but I do know about JavaScript, so this would likely work.

Solution 2:[2]

You can use the chrome extension Edit Url by Regex.

It works by replacing the matching text with the new value.

Provide text to be matched in the Regex textbox and value to replace the matching text in the Value textbox. Then click the submit button. The tab url will now use the new url.

For your case:

Regex: olddomain.com

Value: newdomain.com

Screenshot for chrome extension popup where you need to provide input

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MiffTheFox
Solution 2 CodeZila