-1

I have this string

"551230(95.169%)"

I want only numbers from bracket like 95.169.

stack qtion
  • 171
  • 2
  • 2
  • 5
  • is the value always in parentheses and have a percent sign? have you tried anything? – Nina Scholz Aug 30 '18 at 20:45
  • Yes. value is always in parentheses. I tried using split. but its not work :( – stack qtion Aug 30 '18 at 20:47
  • 1
    Possible duplicate of [Regular Expression to get a string between parentheses in Javascript](https://stackoverflow.com/questions/17779744/regular-expression-to-get-a-string-between-parentheses-in-javascript) – chevybow Aug 30 '18 at 20:51

2 Answers2

2

EZ PZ. Just split twice:

let a = "551230(95.169%)".split("(")[1].split("%")[0]

console.log(a)
connexo
  • 53,704
  • 14
  • 91
  • 128
0

string is an array, you can always get characters from it

var oldstring = "551230(95.169%)"
var newstring = "";

for(i=7;i<14;i++)
{
newstring+=oldstring[i];
}

console.log(newstring);

If you don't know the length of the string, you can create a regex pattern to extract the characters between the parentheses.

\((.*?)\) 

would work

Dani
  • 1,220
  • 7
  • 22