Published on 02 October 2012

Recently I’ve been trying to do lists the long way instead of the longer way. That is to say, if I have a chunk of text that I need to copy somewhere, and it’s not in a good format, I take the time to figure out the regex for it so that I get faster at using regex, rather than just doing it manually. In some cases, this is far shorter - I recently converted a very long dictionary easily after around thirty minutes figuring out a regex for it. Just now, I did something similar, but I could have just deleted some segments a lot faster.

:%s/\s\([A-Z][a-z]*\)\s\S*\s\S*\s\S*\s\S*/\1\r/gc

This basically took a proper noun - in this case, a Japanese town - with for words after it, and removed them, and put it on a new line. As you can tell, I’m using vim. Favourite thing I learned here? \S - anything but \s. I also love () and \1, but that’s just a given, innit?



Tagged: