-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
  • 4,581
  • 36
  • 131
  • 264

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
  • 12,049
  • 2
  • 17
  • 33