Please suggest the need of ^ and $ in this.
Reuse Patterns Using Capture Group
Hints
Hint 1
Given code below:
let testString = "test test test";
let reRegex = /(test)\s\1/;
let result = reRegex.test(testString);
result will match only test test because \1 in this example stands for the same text as most recently matched by the 1st capturing group (test).
If we were to literally translate the regex, it would look something like this:
let re = /(test)\s\1/;
let literalRe = /test\stest/;
Both re and literalRe would match the same t…
Your code so far
let repeatNum = "42 42 42";
let reRegex = /(\d+)\s\1\s\1/; // Change this line
let result = reRegex.test(repeatNum);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
.
Challenge: Reuse Patterns Using Capture Groups
Link to the challenge:
Learn to Code — For Free
Sky020
August 6, 2020, 1:00pm
2
Hello there,
That is what HINT 3 was trying to hint for users to do:
Hint 3
The code below:
let testString = "test test test test test test";
let reRegex = /(test)(\s)\1\2\1/g;
let result = reRegex.test(testString);
because we used \g
, our Regex doesn’t return after first full match ( test test test
) and matched all repetitions. Think about how you can assert the start and end of the string.
But, I did add the last line, as more of a hint.
1 Like
ILM
August 6, 2020, 8:57pm
3
the g
flag doesn’t do that with test method tho, seems a thing from the match
method
it advances the index to which start testing
there should not be suggestion to use g
flag here