Group-Ease (and Subgroup-Ease)
Everything You Need To Know About Subgroups
Issue: 12.3 (May/June 2014)
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 (http://www.mactechnologies.com/index.php:i?page=downloads#regexrx), the popular regular expression editor for Mac and Windows.
Article Description: No description available.
Article Length (in bytes): 12,881
Starting Page Number: 87
Article Number: 12314
Related Web Link(s):
Excerpt of article text...
In the last column, I used a feature of regular expressions called "subgroups" (or "subexpressions") that I hadn't discussed previously, but it's such a core feature of regular expressions that it deserves an in-depth explanation.
Let's say you have tab-delimited text with just two columns, but you want data from the second column only when the first has a particular value. (Yes, this is pretty easy to do with pure Xojo code, but for the sake of illustration, we are going to use a regular expression instead.)
You set up the RegEx with this pattern:
^Match Text\t.*. Translated, that is, start at the beginning of each line and look for the text "Match Text" followed by a tab, then grab all the text that follows it. Lines that have anything other than "Match Text" in the first column will be ignored.
Since you already know what's in the first column, you really only want the text after the tab, but you need to match the first column just to get the second. Sure, you can split the text in Xojo code, but we are going to let the RegEx do the work using a subgroup.
Change the pattern slightly to
^Match Text\t(.*). The parenthesis around the latter part of the pattern tells the RegEx engine to separate this portion of the match. The entire match is a "group" and the text in the second column is a "subgroup".
...End of Excerpt. Please purchase the magazine to read the full article.