DEV Community

Discussion on: A regex cheatsheet for all those regex haters (and lovers) 👀

Collapse
 
nssimeonov profile image
Templar++

I would add "how to reverse the sides of an equation" to this list. There are a few other handy tricks for coders, but this is the most common I can think of right now

Collapse
 
sesc profile image
Sebastian Schleussner • Edited

Yes. If I understand you correctly, that would at the same time be a good example case for another detail I was about to suggest: Match-parenthesis references in the replacement.
Something like:
"a = b + c".replace(/^(.+?) *= *(.+)$/, "$2 = $1")