You're Doing It Wrong
Common Mistakes When Crafting Patterns
Issue: 13.2 (March/April 2015)
Author: Kem Tekinay
Author Bio: Kem Tekinay is a Macintosh consultant and programmer who started with Xojo when it was still REALbasic. He is the author of RegExRX (
Article Description: No description available.
Article Length (in bytes): 12,525
Starting Page Number: 83
Article Number: 13214
Related Web Link(s):
Excerpt of article text...
You have just created a pattern to dissect some complex text. It's a wonder to behold, a thing of beauty, and, if you've used an editor like RegExRX, its colors practically qualify it as artwork.
The only problem is, it doesn't work. It must have a bug in the regular expression engine, right?
Or, just maybe, you have made a basic error that's common to beginners and advanced coders alike. Perhaps it's an error in usage, or one of assumptions, but whatever, there are some "gotchas" to look out for that I'll present here as a series of Do's and Don't's.
DO Keep It Readable
The potential headache with complex patterns often starts with readability. You've created a complex pattern that isn't working, but it's so dense that it's hard to debug even with a dedicated editor. Using free-space mode and comments, as described in the last column, will help a lot here, but so will using tokens that are shorthand for character classes.
To refresh your memory, a character class is a series of characters designated by square brackets that work like an "or" statement. One example might be
to mean any numeral that is either "1", "2", or "3". You can create ranges in character classes using a hyphen so
[1-3]would mean the same thing.
...End of Excerpt. Please purchase the magazine to read the full article.