0

How to replace all the character after certain word using javascript replace method.

For example: "This is sample text."

When ever line contain "sample" then from word "sample" to end of line should replace with "*". The line should be

"The is *"

I know that i have to use regular expression but what should be it i dont know?

1 Answers1

0

Use can use this

<div id="something">this is sample value</div>


var value=$('div:contains("sample")').text();

var newvalue=value.substr(0,value.search( 'sample' ))
StaticVariable
  • 5,253
  • 4
  • 23
  • 45