DEV Community

Discussion on: Untitled Developer Game

Collapse
 
dmfay profile image
Dian Fay
:%s/\(\w\+\)l/\11/g
:w
Collapse
 
philnash profile image
Phil Nash

I feel like this is some vim trickery, but I'm having a time working out what it's going to do and how evil it is!

Collapse
 
mstrodl profile image
Mary

This replaces every l (L) in every "word" with a 1 (one). So: let appleVariable = "goose!"; becomes let app1eVariab1e = "goose!";

Thread Thread
 
dmfay profile image
Dian Fay • Edited

Importantly it doesn't replace the lowercase L if it's the first letter of the word, since many languages won't allow names to start with a number. So the code is much more likely to compile/run than with a simple global replacement, and the victim will find hunting the problems down that little bit harder.

Thread Thread
 
philnash profile image
Phil Nash

That I couldn't see the difference between the l (L) and the 1 (1) in the code example makes this pretty evil! 😈

Collapse
 
dmfay profile image
Dian Fay

Try running it against a short text corpus:

const alpha = beta + gamma;
let delta = epsilon + zeta;
exports.result = alpha + delta;

Much the same effect could be achieved without the capturing group but it wouldn't be quite as sneaky.