Kelsey
Kelsey

Reputation: 931

How To Remove All Text Before a Specific Value in a String

I have the following string, "blahblah
hellothere", that I would like to be shortened to "hellothere" using JavaScript and/or JQuery.

I have tried using the following code:

var titletext123 = "blahblah<br>hellothere"
        var injuryt3xt = titletext123.substring(titletext123.indexOf("<br>") +1);

Which only returns "br>hellothere".

Does anyone have any code which will get rid of the
and all text before it?

Thank you very much. All of your help is appreciated!

Upvotes: 0

Views: 409

Answers (4)

Kevin Boucher
Kevin Boucher

Reputation: 16705

Another option (depending on circumstances) might be:

var injuryt3xt = titletext123.split("<br>")[1];

Which would split the string on <br> and return an array with the left-over parts ... the second of which is referred to with the [1]

Upvotes: 1

Sidd
Sidd

Reputation: 1397

Using regular expression:

var text = "blahblah<br>hellothere"
var clipped = str.replace(/.+\<br\>/, ""));

Upvotes: 1

Satpal
Satpal

Reputation: 133453

You can use split() and get second element.

var titletext123 = "blahblah<br>hellothere" ;    
var injuryt3xt = titletext123.split("<br>")[1];
alert(injuryt3xt);

Upvotes: 1

D. Visser
D. Visser

Reputation: 923

Make it

var titletext123 = "blahblah<br>hellothere" var injuryt3xt = titletext123.substring(titletext123.indexOf("<br>") + 4);

So it is +4. Which accounts for all the characters in <br>.

Upvotes: 3

Related Questions