Regular Expressions in Column Transformation

  • I'm still in learning mode with regular expressions and am attempting a few things during a Trasformation task from one table to another. Basically what I'm trying to to is this: during the copy/import from one table to another, I'm trying to somewhat validate an email field. When it returns valid I want it mapped directly to the corresponding column in the destination, but when it doesn't match to the expression, I want it moved to a different column. What I've got so far is this:

    Function Main()

    Dim objRE

    Dim strExample

    set objRE = new RegExp

    objRE.Pattern = "^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$"

    strExample = TRIM( DTSSource("CAP_EMAIL") )

    ' Test if a match is found

    If objRE.Test(strExample) = True Then

    DTSDestination("CAP_EMAIL") = DTSSource("CAP_EMAIL")

    Else

    DTSDestination("invalidCapEmail") = DTSSource("CAP_EMAIL")

    End If

    Set objRE = Nothing

    Main = DTSTransformStat_OK

    End Function

    It keep returning the following error: ActiveX Scripting Transform '': Function 'reg' was not found in the script.

    Any help would be appreciated.

    -Dan

  • Copule of things that might help.

    1. I never use a local variable that is set with different values each time it runs. I find that the script often falls over. Create a global variable in the procedure and use that to hold the value instead.

    2. I think you need to set .Global = True or false depending upon whether you want to match all occurrences of the pattern. Can't tell you the exact rule from memory.

    Good luck. Everything else looks OK to me.


    ------------------------------
    The Users are always right - when I'm not wrong!

  • tried your suggestions, I'm still getting the same error : function 'reg' was not found in the script.

  • Try reformatting and testing in a different way. This link worked for me OK.

    http://authors.aspalliance.com/brettb/VBScriptRegularExpressions.asp


    ------------------------------
    The Users are always right - when I'm not wrong!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply