Replace a text into a html tag

Hi There,
I have an dynamic output like below
" For all issues pertaining to your account and/or credentials, contact the Contact Center by submitting a request on their site: **."

I wish to have the Url in the output to be transformed into
<a href="https: //login.gov / contact> My link

I know we could do some regex to achieve this. Can someone please guide me on this

Thanks
Umesh k

Hi Umesh,

I understand that what you want to do is to dynamically put information regarding the URL and the displayed text inside the HTML tag for the URL. Is that correct?

You can use variables inside the the HTML tags to dynamically populate the value depending on the user input/situation, for instance <a href="${myURL}">${myText}</a>

You would need to establish the criteria for when which URL and text should be displayed and store these values in the variables. Depending on the amount of URLs that could be displayed, and how you decide which URL should be displayed, you could take different approaches to storing and setting the information, such as a script, a variable or an entity.

Does this answer your question?

regards,
Britta

Hi There,
Thanks for the response. I cannot put the URL in variable. This URL come from a word document which we used in the Rag approach. We somehow need to identify the URL using a regex pattern and then change into anchor tag. I have no control on the data coming out as it is fed from a word document

Hi Umesh,

ok, so the first step would be to detect the URL in the text string that you get back from the document you use in your RAG setup. I suggest you take a look at Regular Expression to Find Urls Within a String for different approaches on how to use regex to find URLs. You may need to iterate over the regex to come up with the version that best suits your needs, depending on the documents you use and the URLs they contain.

Still, identifying the URL would only be the first step in the process of you being able to put this into the HTML tag. I think you would need a series of elements to achieve this

  • a script that identifies the URL in the response text from the RAG
  • a variable in which you store the URL you identify, myURLVar
  • an HTML tag place holder that references the variable <a href="${myURLVar}">${myURLText}</a>
  • a script that replaces the URL you have identified in the text with the HTML tag placeholder

regards,
Britta

Thank you so much for the response.
I have a javascript code whih basically does that

I was trying to use this in the Teneo script and seems like there is a syntax error

Hi Umesh,

The script seems fine for Javascript but scripts in Teneo are written in Groovy. There are some differences, such as the variable or function definition (def can be used for both in Groovy for instance).

You should apply the required changes and remember to consult the Messages section in the Advance TryOut to make sure everything is working as expected.

Let us know if this works!
Kind regards,
Sofía