How to remove part of a string before a “:” in javascript?

后端 未结 1 1418
清歌不尽
清歌不尽 2020-11-30 19:16

If I have a string Abc: Lorem ipsum sit amet, how can I use JavaScript/jQuery to remove the string before the : including the :. For e

相关标签:
1条回答
  • 2020-11-30 20:01

    There is no need for jQuery here, regular JavaScript will do:

    var str = "Abc: Lorem ipsum sit amet";
    str = str.substring(str.indexOf(":") + 1);
    

    Or, the .split() and .pop() version:

    var str = "Abc: Lorem ipsum sit amet";
    str = str.split(":").pop();
    

    Or, the regex version (several variants of this):

    var str = "Abc: Lorem ipsum sit amet";
    str = /:(.+)/.exec(str)[1];
    
    0 讨论(0)
提交回复
热议问题