Rob Rob - 1 year ago 130
Javascript Question

Get Substring between two characters using javascript

I am trying to extract a string from within a larger string where it get everything inbetween a ':' and a ';'.


Str = 'MyLongString:StringIWant;'

Desired Output

newStr = 'StringIWant'

Answer Source

You can try this

var String=str.substring(str.lastIndexOf(":")+1,str.lastIndexOf(";"));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download