Shahmeer Navid
Shahmeer Navid

Reputation: 566

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?

Upvotes: 3

Views: 6448

Answers (2)

Theo.T
Theo.T

Reputation: 9267

Another alternative:

var str = "Remove stuff before this word. Hello!"  
str = str.replace(/.*(?=word)/i, "");

Upvotes: 2

Bert
Bert

Reputation: 82459

Use "substring" combined with "indexOf":

var sample = 'Remove stuff before this word. Hello!';
var substr = sample.substring(sample.indexOf('word')); //substr = 'word. Hello!'

Upvotes: 8

Related Questions