1

I am trying to read a particular number from an expression.

I want to read the digit from below expression.

ID:jv.link.weight:234231

in the above string, I want to read the number 234231 using typescript.

can anyone suggest me any logic how to read this? I am new to typescript.

Jayesh Vyas
  • 1,145
  • 3
  • 15
  • 35
  • Possible duplicate of [Extract ("get") a number from a string](https://stackoverflow.com/questions/10003683/extract-get-a-number-from-a-string) – Roberto Zvjerković May 08 '19 at 09:47

2 Answers2

0

Try this:

getNumber(str) { 
    let number = str.replace(/[^0-9]/g, ''); 
    return number;
}
Seba Cherian
  • 1,755
  • 6
  • 18
0

Use a regex with string.match():

const expression = "ID:jv.link.weight:234231";
expression.match(/(\d+)/g)[0]

Which will return 234231

liamgbs
  • 3,978
  • 1
  • 8
  • 19