-2

I want find text in string and print text to ouput use javascript.

I have a text

Changes: -rw-r--r-- (644)

I want get number in () from this text and print it to alert()

So, how i can do that. Thanks you

  • Possible duplicate of [Find text javascript](https://stackoverflow.com/questions/52261243/find-text-javascript) – Rubén May 18 '19 at 02:14

1 Answers1

0

You can use this:

var m = 'Changes: -rw-r--r-- (644)'.match(/\d+/);
var num = m && m[0];
console.log(num);

It matches the first group of digits in the given string, and extracts those. If no digits were found, num will be null.

Note: alert is not so user-friendly, so I used console.log to show the result.

trincot
  • 317,000
  • 35
  • 244
  • 286