Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Text before Word in Javascript / jQuery?

'Remove stuff before this word. Hello!'

How can I remove the text before 'word' in the above string in javascript or jQuery?

like image 927
Shahmeer Navid Avatar asked May 24 '26 09:05

Shahmeer Navid


2 Answers

Use "substring" combined with "indexOf":

var sample = 'Remove stuff before this word. Hello!';
var substr = sample.substring(sample.indexOf('word')); //substr = 'word. Hello!'
like image 100
Bert Avatar answered May 25 '26 21:05

Bert


Another alternative:

var str = "Remove stuff before this word. Hello!"  
str = str.replace(/.*(?=word)/i, "");
like image 38
Theo.T Avatar answered May 25 '26 21:05

Theo.T