logo

Pro-Tip 2: Text Manipulation With Sublime Text 2

Today I'm going to try and regain some of the reputation I lost the other week when I blogged a "pro tip", which, it turns out, wasn't very pro at all. Talk about egg on my face!

In response to blog Dragon Cotterill pointed me to Sublime Text 2, which did was took me 5 steps in one very simple step. Doh.

I'm now a convert to Sublime Text and using for allsorts of stuff. It's worth a look at if you haven't seen it already.

Anyway, last week I needed to create a Domino-based dropdown list of countries of the world, along with their ISO-3166 codes. The list is available here.

After copy-pasting direct from that webpage in to Sublime Text I had was what you see below. Whereas, what I wanted was a list in the Notes-friendly format "Country Name|CODE".

image

Notice in the lower part of the shot above I've got the Search/Replace function open and have entered the following Regular Expression:

^([A-Z]{2})\s{0,}(.*)$

This looks for a two-letter code at the start of a line, followed by some whitespace, followed by some more text and then the end of a line. It returns matches to the parts inside parentheses as "group matches". In this case the first group match is the two digit code and the second is the country name.

In the "Replace With" box I've told it to change each line to be the group 2 match, then a vertical bar and then the group 1 match. The result looks like this:

image

And that's ready to paste directly in to a Notes field!

Comments

  1. It just a matter of getting used to Sublime. I am an avid Textpad user. I still am for some things such as dealing with large log files and NSDs. But for manipulating the text and writing scripts, Sublime is right up there in flexibility.

    As with anything, it's a matter of finding the right tool for the job.

  2. That's a nice tool. I've long been a fan of EditPlus3 and have recently been getting to know notepad++. Sublime looks like something the toolbox needs for more regex intensive work. Thanks, guys!

      • avatar
      • Aaron Hardin
      • Mon 23 Jul 2012 12:21 PM

      Yes, thank you both very much!!! I too typically use Notepad++ but I like what I see.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Mon 23 Jul 2012

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content