Problem with regular expressions

Tell us what’s happening:

As far as my understanding of this goes
in the above line we place the word we need thats coding
then use the .match to call the line that is matched to it
in case the: extractStr since it contains the word code
yet when i try this it doesn’t work why?

Your code so far


let extractStr = "Extract the word 'coding' from this string.";
let codingRegex = /coding/; // Change this line
let result = extractStr.match(extractStr); // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15.

Challenge: Extract Matches

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/extract-matches

For the sake of legibility, please do not break your lines so short. Just type normally and the layout of the post will handle line breaks naturally.

The .match() function simply takes a regular expression, and applies it to the string it’s being called on. The result is an array of all matches.

You call the .match() function on the string you wish to test against. In your case, you are running it against the string, but feeding to it the string as well. Not a regular expression pattern.

let result = extractStr.match(codingRegex);
1 Like