-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
  • 497
  • 1
  • 10
  • 17

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
  • 64,240
  • 8
  • 67
  • 88