insert an html element inside a textContent of another element

I have an HTML code like this

<p>some text here, also another text here, or any arbitrary position</p>

and I want to replace all occurrences of the word “text” with an anchor, so the result would be

<p>some <a href="#">text</a> here, also another <a href="#">text</a> here, or any arbitrary position</p>

note that it would be a RegExp, for example to replace any /text[^s]/ with a link