How to replace Text with a Regex Regular Expression String in Node.JS
1 min readApr 12, 2020
This mini tutorial covers how to use Regex regular expression strings to replace standard text strings using Node.JS. I’m going to take this down to the simplest level possible, eliminating all of the code that we would normally have to write to set this up. Instead we will just be focusing on results. Let’s look.
So our installation comes before anything else. Let’s use a dependency reference in our package.json to handle this.
"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}
Now our function call goes like this:
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.EditTextApi();var request = new CloudmersiveConvertApiClient.ReplaceStringRegexRequest(); // ReplaceStringRegexRequest | Input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editTextReplaceRegex(request, callback);
With that done, all that we have left to do is enter our information and let the API handle the rest. Super easy.