RegEx Buddy--A Simple Way to Create Regular Expressions |
RegEx Buddy--A Simple Way to Create Regular Expressions by Donnie Tevault The term regular expressions refers to a type of search language. You'd use it to search for text strings that match certain defined patterns. So, if you need to search through a document for email addresses, IP addresses, credit card numbers, Social Security numbers, etc., you'd define a regular expression. For example, let's say that you need to search through system log files for all lines that contain a valid IP address. You'd create a regular expression that looks something like: \b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b If you need to search through a file for email addresses, you'd create something like: \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b Okay, now that you've seen a couple of examples, you can now create regular expressions to do whatever you need done. What?! "No", you say? Don't feel bad. The regular expressions language is quite complex, and is something about which entire books have been written. That's where a helper program, such as RegEx Buddy, can come in handy. There are really only two slight drawbacks to RegEx Buddy.
When you purchase a copy of RegEx Buddy, you'll be given a download link to a customized installation file. (For copyright protection purposes, the filename will contain your own name.) To install it, just enter "wine", followed by the filename. wine SetupRegexBuddy3DonaldTevault.exe On a newer machine, the installation program should come up quite quickly. On the old Pentium III that I used for this demo, it took several seconds. So, if you're using an older machine, just be patient; it'll come up eventually. Once the program does come up, continue the installation as you normally would on a Windows machine. When it's done, you may see some error messages on the command-line, and you may have to hit Ctrl-c in order to get a command prompt back. Don't let that worry you, though. The installation likely completed just fine. To start the program, open the Applications menu, and look for "RegEx Buddy" under the WINE sub-menu. Once the program is up, you can use the point-and-click interface to create your own regular expressions, or choose a pre-defined regular expression from the built-in library. Once you've chosen a regular expression from the library, transfer it to the workspace at the top of the screen with the "Use" menu. If you want to use the regular expression to build your own script in a text editor, use the copy menu to either copy the regular expression "as is", or in a variety of programming script formats. You can also test the regular expression from within RegEx Buddy. When you use this feature, you'll be given the chance to select a file that you want to search through. Any valid IP addresses it finds are highlighted in the output. Okay, this pre-built expression isn't perfect, since the "255" address isn't really usable. But, you can easily tweak it to find only valid Class A, B, or C addresses. In the workspace at the top of the screen, change the expression to: \b(?:(?:22[0-3]|2[0-2][0-3]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b This will exclude any addresses with anything greater than "223" as the first octet. Even with having to make the slight tweak, it's still a lot easier than having to create the regular expression from scratch. There's also a built-in help function, complete with a tutorial on regular expressions. The RegEx Buddy website says that it won't work under WINE, but on my Ubuntu system, it does work somewhat. The first time that I invoked it, WINE asked me if I wanted to install the Gecko library that's required to read the help files. With Gecko installed, the help screen will come up, but is prone to crash. (But, at least it won't take down the RegEx Buddy program itself.) There's also a .pdf help file, if you need to make a hard-copy. All-in-all, it's a nice little program, and it runs quite nicely here on my Ubuntu system. If you're a script developer who needs to create regular expressions on a regular basis, I think you'll find RegEx Buddy to be quite the time-saver. Or, if you just need to learn how to create regular expressions, it can be an invaluable learning tool. Check it out at: http://www.regexbuddy.com |