The Sublime Regex

The Sublime Regex

Table of Contents

Sublime Text is a really wonderful text editor. It’s flexible and extensible enough to cover just about any need, but still simple and clean to use. This post is not a long discussion about either text editors or regular expressions, but a simple post about a problem I needed to tackle and the simple solution.

I pulled a bunch of data from our issue tracking software, and I needed to create a simple list of all the issues resolved and the person assigned the issue. Simple. I grabbed the text I needed from the csv file created, then used a simple find/replace in Sublime Text to put the text in the format I ultimately wanted.

The change is simple. I have a long list of issue summaries followed by a comma and the persons name. All I want to do is find the last comma in each line and replace the comma with a colon and a space.

The sample starts like this:

Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor
Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor
Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor
Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor
Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor
Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor
Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor
Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor
Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor
Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor

The regex is fairly straight forward. Think of it this way, “I want to find the comma that isn’t followed by another comma.” That will guide us to a negative lookahead instead of trying to decipher “the last comma.”

,(?!.*,)

Regular Expressions can be very confusing, and incredibly frustrating. Patience, and plenty of google juice are required. In Sublime Text, open the Find / Replace panel, and select the Regular Expression option.

alter-text

Our regular expression basically says, “find any comma that is not followed by another comma.” Sublime Text, if the option is enabled, shows which items match our find criteria, so it is just a matter of adding the Replace with text and clicking Replace All.

alter-text alter-text

Enjoy!

Tags :

Related Posts

Video Editing Adventures

I have a new role at work. For many years I managed the application development teams, but with recent growth and shifts, I’ve moved to the Marketing and Communications team as an innovation architect. The new role has so many interesting opportunities to learn new skills. One thing I’ve been learning is video editing. Our Marketing team has one videographer. She out-sources a great deal of the filming and editing work, but with limited funds, she does as much as she can personally.

Read More
My finished watch cap

My finished watch cap

I finished my new watch cap! Really happy with how it turned out.

I want to learn more. For my next project, I’m going to give cables a try. I found a recommendation for an easy cabled hat. Will post more as it progresses.

Enjoy!

alter-text

Read More
“Writing the Novel” Lawrence Block

“Writing the Novel” Lawrence Block

alter-text

Lawrence Block is certainly a very successful writer. He currently has178 books listed on Amazon.com. The introduction starts with Mr. Blocktelling us why he wrote this book:

This is a book designed to help you write a novel. It contains thedistillation of my own experience of twenty years as a publishednovelist, plus a considerable amount that I’ve learned from otherwriters. My goal throughout has been to produce the sort of book Imight have found useful when I set out to write my own first novel.

And he does just that. This is a very entertaining and insightful book.Mr. Block shares many experiences with us as well as much hard learnedknowledge. The opening paragraphs sum up these thoughts:

Read More