'在此字词之前删除内容。你好!“
如何在javascript或jQuery中删除上述字符串中'word'之前的文本?
答案 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, "");