-1

I am having the following string 4 (10.3%) and would like to receive 4.

I tried:

let s = "4 (10.3%)"
s.replace("/\s+\((.*?)\)", "");

console.log(s)

However, I still get the initial string back.

Any suggestion what I am doing wrong?

I appreciate your replies!

Carol.Kar
  • 3,775
  • 32
  • 114
  • 229

1 Answers1

1

Use this instead of regex

let s = "4 (10.3%)"
console.log(s.substr(0, s.indexOf(' ')))

Using split

let s = "4 (10.3%)"
    console.log(s.split(" ")[0])
ellipsis
  • 11,688
  • 2
  • 14
  • 33