VOGO Voice – Knowledge Base

How to use Replace Regex function

Estimated reading time: 4 min

In this in-depth tutorial, you will learn how to apply the replaceRegex function to accommodate specific requirements within a voice skill. The comprehensive instructions combined with highlighted screenshots will offer the required directions needed to implement the aforementioned function to strip or remove http/https links and #hashtags from a text. Therefore, this tutorial focuses on using regular expressions to replace the unwanted characters, words, symbols, etc. with blank spaces, strings, numbers, or other characters.


  • VOGO Voice account: https://www.vogovoice.com/
  • Access rights to the Interactions section.
  • Access rights to the Interaction builder platform.

Create a Custom Intent 

Make a suitable intent to be invoked in order to execute a replace regex interaction mapped to it. 
Create an intent titled ‘Replace Regex’ with a suitable sample utterance linked to it. The sample utterance for this intent would be: “What’s happening”. This sample utterance will serve the purpose of fetching the desired feed via the Replace Regex intent.

To learn about how to create a custom intent, visit Creating Intents 

Steps to create an interaction flow

  1. Log into your VOGO Voice account to be directed to VOGO Voice Management Console (https://account.vogovoice.com)
  2. Navigate to Interactions on the vertical bar displayed on the left-hand side of the Dashboard.
    Dashboard > Interactions

3. Now, click on the Interactions button at the bottom right-hand corner of the screen. Select the ‘Replace Regex’ intent to be directed onto the Interaction builder platform.

4. In the flow diagram area, you will be able to see the Start and Response components. 
5. Unlink the Start component from the Response card by clicking the delete icon placed in the middle of the chain.

6. Now, drag and drop an Add Variables component onto the flow diagram area.

7. Connect the anchor symbol of Next on the Start component to the anchor symbol on the Add Variables component. Next, connect the anchor symbol of Next on the Add Variables component to the anchor symbol on the Response component.

8. Now mouse over the top right corner of the Add Variables component. Click on the pencil icon that appears. This will open up its configuration window. 

9. Now, configure the Add Variables component by adding the key-value pairs as shown in the screenshot below. Fill in the first variable name as Story and add the value as People may now play games in new ways thanks to #interactive #voice games, which include interactive stories, adventures, family-friendly games, quizzes, and so on. https://vogovoice.com/solutions/ #voicefirst #voicetech. Then, set the datatype as String.

🖍 Note: The input value for the Story variable includes the text for which we need to remove the url and the hashtags

10. Add the next variable as seen above. Fill in the second variable name as First. To add the value, input the template with the replaceRegex function. This function consists of three arguments. The string, pattern, and replacement. Here var.Story contains the string followed by the pattern /(?:https?|ftp):\/\/[\n\S]+/g which is the regular expression to remove the url from the string and here the replacement is just the blank space. To accommodate this replacement we make use of ” “ Here, set the data type as Template.
first: {{replaceRegex var.Story '/(?:https?|ftp):\/\/[\n\S]+/g' " "}}

11. Next, fill in the third variable name as second. In the variable second, we use var.first as string from which we have already removed the url. var.first is followed by the pattern /#[a-zA-Z]*/g which is the regular expression used to remove hashtags from the string. Here also the replacement will be a blank space which is denoted by ” ” Here, set the data type as Template.
second:  {{replaceRegex var.first '/#[a-zA-Z]*/g' " "}}

12. Next, configure the Response component that is connected to the Add Variables component.

13. Configure the field titled Say by clicking the voice icon on the Response component. This Response component will be used to retrieve the unedited text i.e. the text with url and #hashtags. To fulfill this step, use the template {{var.Story}} in the Say part
Say: {{var.Story}}
Prompt: Say next to continue. 
The same message will be replicated in the Reprompt field.
Reprompt: Say next to continue

🖍Note: The purpose of calling the prompt and reprompt is to route the user to the edited version of the same text; i.e. after removingurl and #hashtags.

14. Populate the field under Expectations by checking the Allow Global Interactions and then select Next from the drop-down list. 

🖍 Note: Ensure to click the Save button to save the interaction flow as and when edits are made.

15. Drag and drop another Response component onto the flow canvas. Connect the anchor icon of the Next on the previous Response card to that of the new Response.

16. Configure the field titled Say by clicking the voice icon on the newly dragged Response component. This Response card will be used to retrieve the edited text. The edited version will be free from any url and hashtags. Input the template {{var.second}} in the Say part. We have already removed the url using var.first and the hashtags using var.second. So var.second will not contain any urls or hashtags.

To learn about different template engines to be followed to run functions visit https://university.vogovoice.com/kb/template-engine/

The screenshot below captures the aforementioned interaction flow.

Testing and Validation 

  1. Click on the Test button next to the Flow Editor button on the interaction builder platform.

2. In the Tests pop-up window that appears, click the + button on its top right-hand corner.

3. Fill in the Name field of the Test Response window that shows up. In the Conversation section of the Test Response, the Replace Regex intent through which this interaction flow has been initiated will be auto-generated in the User invokes field as shown below. 

4. Click the + button within the Conversation Section to open up an additional field titled User Invokes. Ensure to populate this field by selecting the Next intent called to action within the interaction flow. Now, click Save to perform the test.

5. To validate the Test Response, click on the lightning symbol on the left-hand side of the test case. 

6. On the resultant Test Response window, the blue chat bubbles cumulatively present the unedited and edited version of the text within the Response components.

Congratulations! You have successfully learned how to apply the Replace Regex function to make suitable replacements with the aid of regular expressions to accommodate specific requirements.

👍 Note: To test the functioning of the interactions on your device you have to deploy the custom skill to facilitate the skill with the new edits. To accomplish this, click on the Deploy button seen at the bottom of the Skill Settings pop-up window.

To know how to deploy a custom skill visit https://university.vogovoice.com/kb/deploying-a-skill/

To Learn about Add Variables, click here.

Was this article helpful?
Dislike 0
Previous: Retrieving Data from an Array
Next: Conditions