can someone help me to understand how \1\1 works here?
let repeatRegex = /(\w+) \1 \1/; <-------- how this works ?
repeatRegex.test(repeatStr);
repeatStr.match(repeatRegex);
Link to the challenge:
can someone help me to understand how \1\1 works here?
let repeatRegex = /(\w+) \1 \1/; <-------- how this works ?
repeatRegex.test(repeatStr);
repeatStr.match(repeatRegex);
Link to the challenge:
the parentheses in regular expression define a capture group, expression in the parentheses match characters and you can capture the matched characters by numbers starting from 1 preceding them by backslash. if there had been two capture groups e.g. /(\w+)(\d+)/
then you can access the first one by \1
, and second one by \2
. you can learn and practice regex online at regexr.com
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.