Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 14 in printed book and digital formats -- plus a one-year subscription so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 11.4 ('Blackjack')
Instant purchase and download via GumRoad!

REVIEW

Made with Xojo: RegExRX

Issue: 11.4 (July/August 2013)
Author: Marc Zeedar
Article Description: No description available.
Article Length (in bytes): 5,114
Starting Page Number: 16
Article Number: 11403
Related Web Link(s):

http://www.mactechnologies.com/index.php?page=downloads#regexrx

Full text of article...

If you've ever needed to create a regular expression pattern—a "regex"—you know how time-consuming they can be to write and debug. But Xojo developer Kem Tekinay is here to the rescue with his RegExRX application.

The program has a simple three-pane structure, showing your search pattern, the source text (with found items highlighted), and a "match list" listbox which lets you see each subexpression the pattern matched. (Clicking on a match list item highlights it in the source text.)

If you choose the "Replace" tab at the top of the window (versus the default "Search"), two new fields are added to the interface: a replace pattern and a TextArea showing the text after the regex has been run.

All of the fields are resizable; you can drag a widget between them to adjust the size of each field.

In the regex pattern fields, your pattern's syntax is colored to make the various elements easier to identify.

There are also handy "insert" menus which let you quickly insert common regex terms. For instance, there's a "wildcards" category which includes items such as "." (which is any character) and ".+" (any character one or more times). Each menu item is followed by a brief description to remind you what the regex command does.

The categories are well-defined, such as "character classes," "special characters," "repetition," "groupings," "conditionals," "modes," "subroutines," and much more. This makes it fairly easy to find what commands you're seeking.

The "replace" insert menu has different options than the search pattern field.

Once you've figured out your pattern, there's a wealth of export options. You can copy it to the clipboard in a variety of formats, including 4D, AppleScript, JavaScript, Real Studio (Xojo), Perl, and so on. RegExRX is smart about how it builds these patterns, too: the Xojo code it creates includes quotation marks, escaped characters, EndOfLine characters, and line breaks (the underscore character) so that you can simply assign the string to a `regex` object. Here's what a "count words" regex looks like:

"(?xmi-Us) # FREE SPACING MODE—whitespace ignored" + EndOfLine + _

"(?:[^[:punct:]\s[:cntrl:]'‘’]+[’'][^[:punct:]\s[:cntrl:]'‘’]+)" + EndOfLine + _

" # A run of characters that are not a punctuation," + EndOfLine + _

" # whitespace, or control character, followed by a" + EndOfLine + _

" # single quote, then another run of characters that" + EndOfLine + _

" # are not a punctuation, whitespace, or control character" + EndOfLine + _

"| # OR" + EndOfLine + _

"[^[:punct:]\s[:cntrl:]'‘’]+" + EndOfLine + _

" # Just a run of characters that are not a punctuation," + EndOfLine + _

" # whitespace, or control character"

You can also paste a pattern into RegExRX from those same sources (such as Xojo), which reverses the process.

Because each regex you create in RegExRX is its own document, you can save the entire window (patterns, source text, etc.) as a file and restore it at will. This is really handy, as you may not fully debug a regex at one sitting and being able to come back to it later is awesome.

RegExRX is powerful and useful; I know I'll be using it for all my future regex needs. My only complaint is the lack of regex documentation. Granted, there are entire books on regex (and if you're doing complex regex you should definitely invest in one), but it would still be nice if there was some built-in documentation to remind you of the basics. There are sample regex patterns you can download which are educational, and the descriptions on the insert menus are helpful, however. RegExRX is definitely a tool all Xojo developers should have in their toolbox.

End of article.