-3

How to search and replace all words "Hello" and "hello" in string "Hello, lorem ipsum hello and phelloderm" with exception substring in "phelloderm"

beaver
  • 523
  • 1
  • 9
  • 20

1 Answers1

1

Use word boundary \b

"Hello, lorem ipsum hello and phelloderm".replace( /\bhello\b/gi, "$1" ) 

outputs

"$1, lorem ipsum $1 and phelloderm"

gurvinder372
  • 66,980
  • 10
  • 72
  • 94