You can try this

var mySubString = str.substring(
    str.indexOf(":") + 1, 
    str.lastIndexOf(";")
);
Answer from Babasaheb Gosavi on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_substring.asp
JavaScript String substring() Method
The substring() method extracts characters, between two indices (positions), from a string, and returns the substring.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › javascript substring() method: variants and uses
JavaScript substring() Method: Variants and Uses
August 12, 2026 - The substring() method in JavaScript extracts characters from a string between two specified indices.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-string-substr-method
JavaScript String substr() Method - GeeksforGeeks
March 22, 2025 - The substr() method in JavaScript extracts a portion of a string, starting from a specified index position and extending for a given number of characters.
🌐
Refine
refine.dev › home › blog › tutorials › javascript substring method
JavaScript Substring Method | Refine
January 1, 2025 - JavaScript substring() is a String method that is typically used to extract and store part of a string.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substring
String.prototype.substring() - JavaScript | MDN
The substring() method of String values returns the part of this string from the start index up to and excluding the end index, or to the end of the string if no end index is supplied.
Find elsewhere
🌐
YouTube
youtube.com › watch
slice vs substring method | String Object In JavaScript - YouTube
🎁 Join my channel to get access to perks:https://www.youtube.com/channel/UC8n8ftV94ZU_DJLOLtrpORA/join🧡 Hello All JavaScript Lovers Outhere!Today you're go...
Published: July 31, 2022
🌐
YouTube
youtube.com › watch
JavaScript Substring Method in 5 Minutes - YouTube
Learn JavaScript String methods in 5 minutes. In this video, we'll use the substring method to parse out pieces of a JavaScript string by defining start and ...
Published: May 3, 2022
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › slice
String.prototype.slice() - JavaScript | MDN
If indexEnd < 0, the index is counted from the end of the string. More formally, in this case, the substring ends at max(indexEnd + str.length, 0).
Top answer
1 of 9
1238

slice() works like substring() with a few different behaviors.

Syntax: string.slice(start, stop);
Syntax: string.substring(start, stop);

What they have in common:

  1. If start equals stop: returns an empty string
  2. If stop is omitted: extracts characters to the end of the string
  3. If either argument is greater than the string's length, the string's length will be used instead.

Distinctions of substring():

  1. If start > stop, then substring will swap those 2 arguments.
  2. If either argument is negative or is NaN, it is treated as if it were 0.

Distinctions of slice():

  1. If start > stop, slice() will return the empty string. ("")
  2. If start is negative: sets char from the end of string, exactly like substr().
  3. If stop is negative: sets stop to: string.length – Math.abs(stop) (original value), except bounded at 0 (thus, Math.max(0, string.length + stop)) as covered in the ECMA specification.

Source: Rudimentary Art of Programming & Development: Javascript: substr() v.s. substring()

2 of 9
191

TL;DR:

  • If you know the index (the position) on which you'll stop (but NOT include), use slice().
  • If you know the length of characters to be extracted, you could use substr(), but that is discouraged as it is deprecated.

Otherwise, read on for a full comparison

Syntax

  • string.slice(start,end)
  • string.substr(start,length)
  • string.substring(start,end)

Note #1: slice()==substring()

What it does?

  • slice() extracts parts of a string and returns the extracted parts in a new string.
  • substr() extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.
  • substring() extracts parts of a string and returns the extracted parts in a new string.

Note #2: slice()==substring()

Changes the Original String?

  • slice() doesn't
  • substr() doesn't
  • substring() doesn't

Note #3: slice()==substr()==substring()

Using Negative Numbers as an Argument

  • slice() selects characters starting from the end of the string
  • substr() selects characters starting from the end of the string
  • substring() doesn't perform

Note #4: slice()==substr()

If the First Argument is Greater than the Second

  • slice() doesn't perform
  • substr() since the Second Argument is NOT a position, but length value, it will perform as usual, with no problems
  • substring() will swap the two arguments, and perform as usual

The First Argument

  • slice() required; starting Index
  • substr() required; starting Index
  • substring() required; starting Index

Note #5: slice()==substr()==substring()

The Second Argument

  • slice() optional; the position (up to, but not including) where to end the extraction
  • substr() optional; the number of characters to extract
  • substring() optional; the position (up to, but not including) where to end the extraction

Note #6: slice()==substring()

What if the Second Argument is Omitted?

  • slice() selects all characters from the start-position to the end of the string
  • substr() selects all characters from the start-position to the end of the string
  • substring() selects all characters from the start-position to the end of the string

Note #7: slice()==substr()==substring()

So, you can say that there's a difference between slice() and substr(), while substring() is basically a copy of slice().

If you want substr's functionality:

"foobarbaz".substr(index, length);

without using a deprecated feature, you can just do:

"foobarbaz".substring(index, length + index);

And get the exact same results bar all of the edge-cases, like negative index/length.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substr
String.prototype.substr() - JavaScript | MDN
1 week ago - The substr() method of String values returns a portion of this string, starting at the specified index and extending for a given number of characters afterwards.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-substring-examples-slice-substr-and-substring-methods-in-js
JavaScript Substring Examples - Slice, Substr, and Substring Methods in JS
March 22, 2020 - This method basically gets a part of the original string and returns it as a new string. The substring method expects two parameters: ... Let’s see the usage in an example. Suppose that we have the example string below: const myString = "I am learning JavaScript and it is cool!";
🌐
Ultimate Courses
ultimatecourses.com › blog › substring-in-string-javascript
Find a Substring inside a String in JavaScript - Ultimate Courses
May 29, 2020 - Visually we can see that findme contains 'bacon' but how do we get a yes/no answer in JavaScript? We can introduce a new feature in ES6, the String.prototype.includes method, which will return us a Boolean value based on whether the substring was found:
🌐
Mimo
mimo.org › glossary › javascript › substring
JavaScript Substring Method: Learn String Extraction
The substring() method in JavaScript extracts a portion of a string and returns it as a new string without modifying the original string.
🌐
Edureka
edureka.co › blog › javascript-substring
JavaScript Substring() | How is it different from substr() & slice()? | Edureka
January 9, 2025 - This Edureka blog is about the JavaScript substring() whih is an inbuilt function that returns a part of the given string from start index to end index.