var str = "On the 10th, all 4 employees got a $3.50/hour raise."
var arr = str.match( /\d+[\.\d]*/g ); // 'g' modifier to capture ALL matches
alert( arr.join("\n") ); // Show one match per line - click to run ->
• Our "/\d+[\.\d]*/g" pattern, translated in plain English: "capture all numbers that contain one or more digits (\d+), optionally (*) followed by a period and one or more numbers (\.\d)".
• Without using the 'g' global modifier, only the first number would have been captured .
• match() stored each new matching string into an array, which we saved into the arr variable.
• We used the join() method to display one element per line (does not modify the original array).
var str = "On the 10th, all 4 employees got a $3.50/hour raise.";
if( ( str.match(/\d+[\.\d]*/g)).length < 3 )
alert("You have not used enough numbers!");
alert("Thanks for using at least 3 numbers.");
$str = 'On the 10th, all 4 employees got a $3.50/hour raise.';
// No 'g' modifier needed: this function auto-captures all matches:
preg_match_all( '/\d+[\.\d]*/', $str, $arr );
// Array of matches found stored inside $arr
// Use count() function to get the length of that sub-array:
echo 'We found ' . count($arr) . ' numbers in that string';