-1

I am trying to wrap each word in HTML string with a span tag. The following regex is working but I am getting error sometimes invalid regular expressions in react native ios and android both and it may be due to negative look behind can anyone help to replace this regex?

htmlStr.replace(/(?<!(<\/?[^>]*|&[^;]*))([^\s<]+)/g, ‘$1<span class="word">$2</span>‘)
bittu
  • 337
  • 2
  • 13

1 Answers1

1

JavaScript Regex does not support lookbehind, which is a well-documented fact to the point you've answered your own question. JavaScript has plenty of ways to match a substring within a string, so I'd definitely start with that instead of overengineering a regex grab.