0

how would use replace in node js?

HTML:

<p> <a href="https://www.abc.co/">https://www.abc.co/</a> Lorem ipsum dolor sit amet, praesent justo sem suscipit dolor,<a href="https://www.abc.co/">https://www.abc.co/</a> maecenas pellentesque ligula vestibulum in vivamus eu </p>

I try:

const variableabc = document.getElementsByTagName('p');
const result = variableabc.replace('/(https?:\/\/[^\s]+)/g','<a href="$1">$1</a>');

Expected output:

https://www.abc.co/
https://www.abc.co/
Ravi Kumar Gupta
  • 1,698
  • 2
  • 22
  • 38
Sagar Mistry
  • 131
  • 11
  • 2
    You have to explain where exactly your problem is, because each of the parts is most certainly already answered here on SO. Besides that, server side DOM manipulation that supports things like `getElementsByTagName` requires a module, so if you use a module you have to mention which one. `getElementsByTagName` returns an `HTMLCollection` and you have to iterate over that. – t.niese Dec 26 '18 at 07:23
  • See https://stackoverflow.com/q/10693845/215552 to fix the issue in the code. The question in the title does not seem to match the code presented. – Heretic Monkey Dec 26 '18 at 08:05

0 Answers0