I am currently working on a React project and I've encountered a challenge. I have a text response that I need to parse in such a way that any URLs in the text are converted to clickable hyperlinks ( tags). Additionally, I have a requirement where I need to highlight certain words within the text based on a provided search value.
This highlighted text isn't part of the URL, it could be anywhere within the text response.
For example, given this text: "Hello, check out https://www.example.com for more details. The example site is really useful."
If my search value was "example", I'd want to generate:
<span>
Hello, check out <a href="https://www.example.com" target="_blank">https://www.example.com</a> for more
details. The <mark>example</mark> site is really useful.
</span>
Where "https://www.example.com" is a clickable hyperlink and "example" is highlighted.
Any suggestions on how to achieve this in React would be highly appreciated. Thank you!