Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Regex evaluation step

  1. #1
    Join Date
    Nov 2007
    Posts
    12

    Default Regex evaluation step

    Hi,

    I wanted to use the Regex evaluation step to extract a date from a file name that was already assigned to a field by the preceeding step (Text file input in this case). But I failed as the only thing that Regex step evaluated was true or false.

    My question is if there is some way how to get the match of the Regex evaluation into a field? I did not find the documentation for the Regex evaluation within the Spoon user guide, so I am asking here.

    To be concrete: my files are named xyz-YYYY-MM-DD.gz where the YYYY-MM-DD string is the date I want to extract. I tried following expression:
    ([0-9]{4}\-[0-9]{2}\-[0-9]{2})
    Then I tried basic expressions like .+ to match the whole string but I am still getting only true or false result.

    Any ideas?

    Petr

  2. #2
    Join Date
    Mar 2007
    Posts
    216

    Smile

    Hi,

    I have a problem like upside :
    Input :
    Code:
    c:\test\foo,bar.txt
    c:\test\barfoo.txt
    Output wanted :
    Code:
    foo,bar
    barfoo
    My regex returning True : .*\\([\w^\,]*).txt The variable I would return : $1 = foo,bar and $1 = barfoo
    Any help on how to use Regex evaluation step ? (I also managed to crash Kettle while previewing a test transformation)
    A good website for evaluating you regex : http://www.cuneytyilmaz.com/prog/jrx/

    a+, =)
    -=Clément=-
    Last edited by clement; 11-21-2007 at 10:22 AM. Reason: changed the regex

  3. #3
    Join Date
    Nov 2007
    Posts
    12

    Default alternative solution

    Hi,

    unfortunately I still do not know how to use the RegEx step. But instead of it I currently use Modified Javascript Value step with the following script:

    var re = new RegExp("([0-9]{4})-([0-9]{2})-([0-9]{2})");
    var matched = re.exec(uulog_name.getString());
    if(matched) {
    action_date = new Date(matched[1], matched[2] - 1, matched[3]);
    }

    Where uulog_name is a name of my input field and action_date variable is listed within the Fields list box i.e. it is added as additional output field. It works well for me.

    Petr

  4. #4
    Join Date
    Mar 2007
    Posts
    216

    Smile

    Hi,

    Thanks, I did a transformation with your method and the "Get Filenames" step, it works (I attached it).
    Here is my code :
    Code:
    var re = new RegExp("(.*)\.txt");
    var matched = re.exec(short_filename.getString());
    var output="";
    if(matched) {
    output=matched[1];
    }
    a+,=)
    -=Clément=-
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.