在Javascript / jQuery中删除Word之前的文本?

时间:2011-11-26 01:53:11

标签: javascript jquery

'在此字词之前删除内容。你好!“

如何在javascript或jQuery中删除上述字符串中'word'之前的文本?

2 个答案:

答案 0 :(得分:7)

使用" substring"结合" indexOf":

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

答案 1 :(得分:1)

另一种选择:

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