Page 1 of 1

Stages that support regular expressions (regex)

Posted: Mon Feb 26, 2007 8:38 pm
by timsmith_s
I have read posts regarding regular expression in filters, but would anyone please help with understand if the Modify or Transformer stages support them too? Can they be used for parsing values, or only to exclude records?

Thx - T

Posted: Mon Feb 26, 2007 9:58 pm
by ray.wurlod
The answer to your first question is NO, which makes your second question moot.

A Filter stage uses something like regular expressions in its WHERE clause, but does not support the full gamut of regular expression functionality.

Posted: Tue Feb 27, 2007 12:58 am
by kumar_s
External Filter stage can be leverage more for this purpose.

Posted: Tue Feb 27, 2007 3:17 am
by jhmckeever
It is possible to use regular expressions in parallel transformers, but only after you've done all the hard work yourself...

You can define a Parallel Transformer by creating a C function using the <regex.h> library. We're using this at the moment and it works well. It provides full regular expression support in parallel transformers and performance is pretty good too. You can get extended expression support using the REG_EXTENDED flag.

Let me know if you require further details. If you want a place to start, lookup the 'regcomp' and 'regexec' functions in the library.

J.

Posted: Tue Feb 27, 2007 5:01 am
by kumar_s
jhmckeever, you mean you have created a BuildOps?

Posted: Tue Feb 27, 2007 6:11 am
by jhmckeever
DOH! Sorry - That post was typed Pre-Coffee (hence my excuse for a brain wasn't awake).

Nope, I created a Parallel Routine (Not 'parallel transformer'), referencing a function I defined in a custom C library.

By way of payment for my daft error, here's the code ...

Code: Select all

#include <sys/types.h>
#include <regex.h>

int matchRegexp(char *inString, char *inPattern)
{
    int i;
    regex_t re;
    char buf[256];

    i=regcomp(&re, inPattern, REG_EXTENDED|REG_NOSUB);
    if (i != 0) {
        (void)regerror(i,&re,buf,sizeof buf);
        /* printf("%s\n",buf); */
        return(0);			    /* report error */
    }
    i = regexec(&re, inString, (size_t) 0, NULL, 0);
    regfree(&re);
    if (i != 0) {
        (void)regerror(i,&re,buf,sizeof buf);
        /* printf("%s\n",buf); */
        return(0);			    /* report error */
    }
    return(1);
}
Rgds,
John.

Posted: Tue Feb 27, 2007 9:33 am
by timsmith_s
Thank you.

Posted: Tue Feb 27, 2007 4:55 pm
by kumar_s
Search for "Editing Multiple Derivations" under transformer section in the Parallel Job Developer's Guide. There is something mentioned for Regular expression. I haven't gone through it fully.