DEV Community

Discussion on: Explain Regular Expressions Like I'm Five

Collapse
 
mellen profile image
Matt Ellen

"Find every character that's not a letter" isn't just those 4 characters:

var poem = `Twinkle twinkle little star,
How I wonder what you are!
Up above the world so high!
Like a diamond in the sky!`

poem = poem.replace(/[^A-Za-z]/g, "❤️")
console.log(poem)

/*
result:
Twinkle❤️twinkle❤️little❤️star❤️❤️How❤️I❤️wonder❤️what❤️you❤️are❤️❤️Up❤️above❤️the❤️world❤️so❤️high❤️❤️Like❤️a❤️diamond❤️in❤️the❤️sky❤️
*/