Bob Belderbos On X: "Forget Python For A Sec, Here'S How Vim Helped Me Out Today ... 💪 📈 Ever Felt Like You Needed A Quick String Replacement Without Diving Into A Script? Here'S A Vim Trick I Just Used ... I Wanted To Replace All Occurrences Of: Name,[email protected],0,171,,2023-09-21 With:…" / X

edit✏️

Here's my thought on Bob Belderbos on X: "Forget Python for a sec, here's how Vim helped me out today ... 💪 📈 Ever felt like you needed a quick string replacement without diving into a script? Here's a Vim trick I just used ... I wanted to replace all occurrences of: name,[email protected],0,171,,2023-09-21 With:…" / X


I need to learn regex capture groups better. This is so dang powerful. I really like the \v that bob uses here, it really does cut down on the terseness of all the special characters.

I wanted to replace all occurrences of:

name,[email protected],0,171,,2023-09-21

With:

name,[email protected]

Easy to do with Python, but what about a bit of > regex in Vim?

:%s/\v([^,]+,[^,]+),.*/\1/


This post was a thought by Waylon Walker see all my thoughts at https://waylonwalker.com/thoughts