Match All Numbers
Hints
Hint 1
- A global flag will help you get through this challenge.
Hint 2
- Try using a shorthand character for
digits.
digits.My initial code for this was:
// Setup
var testString = "There are 3 cats but 4 dogs.";
// Only change code below this line.
var expression = /\d+4/g; // Change this line
var expressionToNumbers = testString.match(expression).length;
// Only change code above this line
// This code counts the matches of expression in testString
var digitCount = testString.match(expression).length;
But I got issues with line #6. I just fixed it up now and came up with this:
