5 ms·
What does it mean when a reg ex ends with a `\1` (backslash 1) as in this example third beginner puzzle? (.)+\1 http://regexcrossword.com/challenges/beginn
by Edmontonian 12y ago
What does it mean when a reg ex ends with a `\1` (backslash 1) as in this example third beginner puzzle? (.)+\1
http://regexcrossword.com/challenges/beginner/puzzles/3 http://regexcrossword.com/challenges/beginner/puzzles/3
- tlrobinson 12y agoIt's a backreference to the first capture group, which is denoted by the first set of parenthesis, e.x. (.*)+\1 would match "ABAB", or "ABCABC", etc. "\2" would match the second capture group, e.x. (.*)(.*)\2\1 would match "ABBA", or "AABBBBAA", etc.
- Edmontonian 12y agoso in your first example, "AB" was in the capture group and the \1 repeats it?
- tlrobinson 12y agoCorrect. The following (.*)\1+ Would also match "ABABAB", for example.
- deleted 12y ago[deleted]
- deleted 12y ago[deleted]
- eru 12y agoLook at the Help button (top right); that explains all their syntax.
- Edmontonian 12y agoThe help button doesn't really explain that point ( I don't think) at least not in a very clear way for someone inexperienced with regex
- Ygg2 12y agoSpeaking of that puzzle how come [COBRA]+ and (.)+\1 give back result 'O'? Why not C or B or A?
- cyborgx7 12y ago(.)+\1 means the last letter has to be equal to the first letter. (AB|O|OR)+ dictates that the last letter of the first row has to be A or O [^ABRC]+ makes it so that the lower right square can't be B therefore the upper right square can't be A