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
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
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.