I want to be able to get a string in between a bracket opened (
and a bracket closed )
.
myString = "MT Mokwa (40,000)"
How can I get 40,000
from the string?
I want to be able to get a string in between a bracket opened (
and a bracket closed )
.
myString = "MT Mokwa (40,000)"
How can I get 40,000
from the string?
Both of these examples assume that the string will always have a set of parenthesis, opening before closing.
I suggest using substring and indexOf for this:
var result = myString.substring( myString.indexOf( '(' ) + 1, myString.indexOf( ')' ) );
You can also use a regex if you prefer:
var result = /\(([^)]*)\)/.exec(myString)[1];