Situation: Suppose you are working on a web app which fetches content from your REST API available at http://my-app-server.com/rules
. You have cloned the API server, made some changes and running it locally on http://localhost:4000/rules
. Now, you want to test your app with the new changes done on API server.
Approach 1
Change the domain in your App code to hit localhost
instead of my-app-server
. Once your testing is done revert this change.
Approach 2
Use Replace Rule Define a Replace Rule to replace http://my-app-server.com
with http://localhost:4000
in all URLs. No need to change url inside your code. After your testing, just disable the rule. As simple as that.
Here is a review listed on Chrome Store about Replace Rule.
You can change the values of query parameters present in URL. For example: Changing ?dl-0
to ?dl=1
in dropbox URL downloads the file directly without going to the usual preview page. Such a simple use case of Replace Rule.
Often you may find that links to some documentation or blog posts are changed but you have developed a typing habbit of old urls. Well, you can use replace rule to achieve that use case.
With all the use cases mentioned above, we know Replace Rule can be used to replace a string with another string in a Url. Apart from it, Replace Rule can also match a JS Based Regex
in the Urls and you can replace them with another string. Please note in case of Regex pattern, you can also use the values of group expressions in your regex and use them in final strings. For Example:
/(https:\/\/[^\/]*)(.+)(\.jpg)$/i
$1 is the value of 1st group expression. – DomainName
$2 is the value of 2nd group expression – PathName but not file extension
$3 is the value of 3rd group expression – File extension .jpg
in this case
Replace /(.+)(\?)(.+)/ig With $1
$1 is the value of URL before “?”
$2 matches “?”
$3 is your query string
Checkout this Regex on regex101 and try your use cases.
You can use Regex 101 for creating your Regex and try out various scenarios.