puzzle, regex (screenreader-unfriendly)
So, here's a regular expression (JS flavour):
^(?=( +|\t+))\1(?:\t| )
This regex matches (at the start of a line) both "1+ spaces followed by a tab" and "1+ tabs followed by a space", but it does *not* match a sequence of just spaces or just tabs.
How does it work?
(Make sure to CW your answers please!)
re: solution
@autumnull All of that is correct, but what role do the lookahead and backreference play here?
re: solution
@autumnull Bingo, that's exactly it :)
re: solution
@joepie91 neat little puzzle <3
re: solution
@autumnull I actually found it in a real-world codebase that I was auditing! It was in ESLint, and I was staring at it for like 10 minutes before I finally realized how it was meant to work, and figured it'd be a neat puzzle to share :D
re: solution
@joepie91 disables the backtracking down alternate paths and locks it into the “i’ve matched all the characters on this line” route