How to remove part of a line before ":" in javascript?

If I have the line "Abc: Lorem ipsum sit amet", how can I use javascript / jQuery to delete the line before ":", including ":". For example, the line above would become: "Lorem ipsum sit amet".

+52
javascript
Nov 03 '10 at
source share
1 answer

There is no need for jQuery, normal JavaScript will do:

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

Here you can test it . Or .split() and .pop() :

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

You can test this version here . Or, a regex version (several variations of this):

 var str = "Abc: Lorem ipsum sit amet"; str = /:(.+)/.exec(str)[1]; 

You can check it out here .

+156
Nov 03 2018-10-03T00:
source share



All Articles