freeCodeCamp Challenge Guide: Find Numbers with Regular Expressions

freeCodeCamp Challenge Guide: Find Numbers with Regular Expressions
0

#1

We can use special selectors in Regular Expressions to select a particular type of value.

One such selector is the digit selector \d which is used to grab the numbers in a string.

It is used like this: /\d+/g.


#2

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: