Find More Than the First Match

Tell us what’s happening:

I don’t know what else to do?

Your code so far


let twinkleStar = "Twinkle, twinkle, little star";
let starRegex = /search/gi; // Change this line
let result = twinkleStar; // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/find-more-than-the-first-match/

Hi,

Try to use the information provided on the left side of the exercise to guide you here. Currently your regex is looking for the characters “search” instead of twinkle and you are not using “match” on the last line to check the string versus the regex.

Hope that points you in the right direction :pineapple:

let twinkleStar = “Twinkle, twinkle, little star”;
let starRegex = /search/gi; // Change this line
let result = testStr.match(twinkleStar); // Change this line

That?

You’re getting closer, but your regex needs to updated to look for twinkle instead of search /search/gi and also you are using match incorrectly with something that doesn’t exist (testStr). You’ll want to run match on twinkleStar against your regex.

let twinkleStar = “Twinkle, twinkle, little star”;
let starRegex = /twinkle/gi; // Change this line
let result = testStr.match(twinkleStar); // Change this line

I change from search to twinkle but I don’t understand what to do with line below?!

// running test
testStr is not defined
testStr is not defined
testStr is not defined
testStr is not defined
// tests completed

And tell me that!

That’s because there is no testStr. You should be running match on something that is available (twinkleStar) and pass in the regex variable (starRegex). You should not have testStr anywhere in your code as it was a variable specific to the example on the left.

And what I should write because nothing it is right.

twinkleStar.match(starRegex)

So there you run the match function on twinkleStar and pass in your regex that was saved as starRegex.

1 Like

Thank you I got it it is so simple.

1 Like