Match string which doesn't start with

Posted by Pinky on Stack Overflow See other posts from Stack Overflow or by Pinky
Published on 2013-06-28T16:03:15Z Indexed on 2013/06/28 16:21 UTC
Read the original article Hit count: 213

Filed under:
|

I have a string that looks like this:

var str = "Hello world,  hello >world, hello world!";

... and I'd like to replace all the hellos with e.g. bye and world with earth, except the words that start with &nbsp or &gt. Those should be ignored. So the result should be:

bye earth,  hello >world, bye earth!

Tried to this with

str.replace(/(?!\ )hello/gi,'bye'));

But it doesn't work.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex