Hitachi Vantara Pentaho Community Forums
Results 1 to 11 of 11

Thread: Regex Allowing Invalid Fields Pass Through !!!

  1. #1
    Join Date
    Jun 2010
    Posts
    10

    Default Regex Allowing Invalid Fields Pass Through !!!

    Hi Guys
    Having a little problem with a Regex in the JavaScript Step of Pentaho. It seems when I say the field has to be exactly 36 in length i.e. {36} the Regex can tell the difference between good and bad data. Theproblem comes when I use From 1 to 36 i.e. {1,36}, which seems to be allowing Bad data through. Please see example below:

    var profile_regx=/[a-z0-9A-Z\/\\&._\-]{1,36}/; <--- Dosen't Work
    var profile_regx=/[a-z0-9A-Z\/\\&._\-]{36}/; <--- Work's Fine
    var fail_reason="";
    var CRITICAL_FLAG="F";
    var PROFILE_FLG="FAIL";
    //********************* PROFILE_COOKIE ************

    if (ltrim(rtrim(PROFILE_COOKIE)).match(profile_regx)) {
    PROFILE_FLG = "PASS";
    } else {
    CRITICAL_FLAG = "T";
    fail_reason=fail_reason + "PROFILE_COOKIE, ";
    }

    Obvously I only use one or the other Regex shown in the example at a time. They are not both in the code like at the same time like shown above. The data I pass in is as follows as a String type:

    1.2KfJ654/6473HDUqiee8745-j74.HEu22+

    If anyone has any idea's that would be most appreciated. Please also see attached the Transformation as well :-).

    Thanks
    Simon
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2008
    Posts
    143

    Default

    Could you provide more data sample (to test the Regex)?

  3. #3
    Join Date
    Mar 2008
    Posts
    140

    Default

    I am getting the opposite result {1,36} is working for me while {36} fails. If I change {36} to {35} it works, as though it is working from a 0 index... not sure what exactly is going on here just yet.

    Furthermore, a javascript cookie.length produces the expected string length of 36.

  4. #4
    Join Date
    Mar 2008
    Posts
    140

    Default

    I tried .{36} and it works... so the length shouldn't be a problem.

  5. #5
    Join Date
    Mar 2008
    Posts
    140

    Default

    Add a + to your regex, it's in the string and not in your list of characters.

  6. #6
    Join Date
    Mar 2008
    Posts
    140

    Default

    I just read too that the {1,36} seems to be allowing bad data through... what does your bad data look like?

  7. #7
    Join Date
    Jun 2010
    Posts
    10

    Default

    The plus is supposed to be there as this is not allowed in the String and I want it to fail the Regex but when I use {1, 36} its seems to accept the + character when it shouldnt.

    Thanks
    Simon

  8. #8
    Join Date
    Nov 2008
    Posts
    143

    Default

    Have you managed to fix it, Simon?
    If not, please post more samples of good and bad data so we can speed up testing.

  9. #9
    Join Date
    Feb 2009
    Posts
    296

    Default

    Have you tried anchoring your RegEx?
    var myRegEx = /^RegEx$/
    Fabian,
    doing ETL with his hands bound on his back

  10. #10
    Join Date
    Jun 2010
    Posts
    10

    Default

    Hmm... Anchoring seemed to fix my problem but I am a bit confused why. Could you explain the purpose of the Anchor as I have not really used this before if you dont mind of course :-)

    Thanks
    Simon

  11. #11
    DEinspanjer Guest

    Default

    ^ anchors the expression at the beginning of the field. $ anchors it at the end of the field. Without those, your regex is allowed to match some substring of the field instead of the entire contents.

    So in your case, it is matching just the part in green below:
    1.2KfJ654/6473HDUqiee8745-j74.HEu22+

    http://www.regular-expressions.info/ is a good site to bookmark when you run into problems such as this, or want to learn more about regexes.

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.