Regular Expressions in Notepad++

I’ve always found regular expressions to be a real un-intuitive mind-bender. I’ve had some very limited success in using them…mostly in a linux command-line grepping situation where I had some very good examples to work from and had no other choice…i.e. I was FORCED to use them. I’m a programmer. I’m a database administrator. I enjoy coding and writing weird SQL! But I’ve never been able to get my head around regular expressions…never really wanted to. See my blog post about my laziness with regular expressions. 😉

I’ve been using Notepad++ for some time now and have sort of a love-dislike relationship with it because it’s very powerful…but some things, notably macros don’t exactly work like I’d want them too…and sometimes, I really think they’re buggy.

Today, I needed to take a list of e-mails and, for each email take the part before the ‘@’ and copy it at the of the line with a tab in between.

So, to start with I have a list of emails like this:

lkjshdflkhsf [at] lkjhsdf [dot] com
oiuyeruyq [at] iuywer [dot] com
nbxvnxbv [at] mnbcx [dot] com

At the end I need lines like this:

lkjshdflkhsf [at] lkjhsdf [dot] com[TAB]lkjshdflkhsf
oiuyeruyq [at] iuywer [dot] com[TAB]oiuyeruyq
nbxvnxbv [at] mnbcx [dot] com[TAB]nbxvnxbv

If you’ve ever had to move contacts from one piece of software to another you may have come across this problem to create an import file for the destination. If Notepad++ macros worked in every situation, I’d have been able to use them, but they would simply “malfunction” on me and not allow me to accomplish this. So I played with regular expressions and became aware of how you can “tag” parts of your search expression and then refer to those tagged portions of text in your replacement string to allow you to move things around and copy things. Really good regex info can be found on the Notepad++ wiki here:

So to accomplish this I was able to use the Notepad++ Search/Replace dialog in “regular expression” mode like this:


In the image, you can see that in the FIND expression, you have two sections in parentheses. This is how you tag a portion of a string, by putting the expression within parentheses. For the first piece, it tags the part between the beginning of the line, signified by the “^” (caret) character and the “@”, signified by itself. The “dot asterisk” means:

  • dot = any character
  • asterisk = zero or more times

I’ve shaded that yellow. Then the second section that I’ve tagged is between the “@” and the end of the line, signified by the “$” (dollar sign). I’ve shaded it orange.

Now, in the replacement, you can refer to these tagged areas by “1”, “2”, “3”, etc….simply the order in which they appear gives them an ordinal number. You can then refer to them in the replacement string several times if you wish.

I’m still quite the noob in regular expressions and much more can be done with them. But, I found this particular example to be something that I can definitely build on in the future and hope that you can too.

The Greatest Thing Since Sliced-Bread For All My Dough…

…Or “programming” Quicken 2005 with Autoit

It’s the most wonderful time of the year again…Tax Time!

Sheesh! Don’t all blow your party horns at once! ;c)

I’m no fan of this necessary evil either. Each year I hope and seek for ways to make it more streamlined. Necessity is the mother of invention and all that. I’m a entrenched but somewhat reluctant user of Quicken to “manage” my financial world and every year about this time I have to shore up my financial tracking practices a bit retroactively to make sure that I have my ducks sufficiently aligned to make sense of the US Tax code.

<rant>As I alluded to earlier…I think taxation is necessary. I think the US Tax code is what is evil!</rant>

It’s not the only thing that is sometimes “evil” however. Quicken/Intuit fights hard, it often seems, to gain entry into that which is collectively thought of as the “axis of evil” in the consumer computing world. Anyone who’s upgraded to Quicken 2005 will understand that more was taken away than gained for many users. As I consider the way that the false god/evil spirit of Mammon works, then it is not too surprising to see these sorts business practices of those in the financial software industry.

Quicken does many, many things and most are done well. But…it remains a closed system. If what you want Quicken to do or how you want it to do it wasn’t conceived of by the software engineers at Intuit, you’re pretty much stuck. Using Colin Smale’s excellent program MT2OFX (no longer findable on the web) however, I’ve succeeded in incorporating my French bank account into Quicken along with my American one. Works like a champ…in spite of how Quicken is designed. That’s at least one success story of how Quicken can be made to work the way you want it to.

Admittedly, our situation is far from mainstream in the financial world. As American missionaries in France, we’re into “international finance” with very little money! So, we’re not the typical Quicken target customer…but I still want my financial software to be a tool useful to me and not me some sort of pawn in its hands.

Anyway, in seeking how to get some transactions from a “cash account” in Quicken into a “split” transaction in another “non-cash” account to allocate “cash” usage from an ATM withdrawal, I was stymied as to how I could make it happen without simply re-entering all the transactions.

Manual labor alert!!! Manual labor alert!!!

…enter Autoit

Autoit is a freeware scripting package that allows you to automate virtually anything that you can get at with your keyboard and/or mouse in a Windows environment. I am simply stunned by its capabilities and the attention to detail in the suite of tools that comprise Autoit. It’s put out by a group called “Hiddensoft” and I think that they somehow must think being “hidden” is better! ;c) I troll around a lot of freeware sites and am always looking out for good freeware. What’s more, by “profession” I was a programmer and I’m a bit of a “scripting junkie”. I’m no expert but I’ll gladly script for hours to save 5 minutes (which I justify by the thought that eventually I’ll save time in the long run…and in fact, I’m still pretty convinced of my logic in that! ;c))

Anyway, I’d not come across this gem until last week (which on one hand makes me mad…considering some of the very well-known freeware and over-advertised “shareware” out there…they say it’s been around since 1999…hidden!). Don’t even remember how I stumbled across it, but I was probably searching for something like “automate quicken” and found it. This thing is too good to remain “hiddensoft”!

Not only are the capabilities of this software amazing and, I think, pretty unique, the endless supply of help in the actual coding task is really stunning…especially for a scripting language…especially for freeware.

It’s a “basic-like” scripting language (VB, VBA, VBScript familiarity will carry you far in quickly coming up-to-speed in using this language). If needed it supports a GUI interface and 2 different GUI creators are included in the package, though certainly batch scripts are normal too. It has a keystroke and mouse movement recorder for jump-starting automating human interface actions. It comes with a version of the Scintilla/SciTE editor (also used as the base for such editors as NotePad++) that has all sorts of automated coding aids. The help is excellent and integrated very well with the editor (including autocompletion, etc.). It comes with a dll version of the script engine so that you can combine Autoit with other scripting languages like VBScript (i.e. “extend” VBScript capabilities). You can compile your scripts into an exe file, etc., etc.

Anyway, I’ve been heavy into it for the past week coding this Quicken-automation script…which speaks much more about the frustration of using Quicken (which doesn’t always expose enough info in its interface) than of the capabilities of Autoit. I’m not the best marketer so, I’ll just say that if you have a Windows app and some repetitive tasks and no good way to marry those two together (and can script your way out of a wet paper bag), get on over to today and find your solution. You may find that it becomes your scripting solution of choice as well.