Hitachi Vantara Pentaho Community Forums
Results 1 to 10 of 10

Thread: Regular Expression Help

  1. #1
    Join Date
    Feb 2007
    Posts
    21

    Default Regular Expression Help

    Can someone help me with a regular expression that will match a string will all the same letters or digits and no others? Eg. ddddddddd or 8888888. I wish to use it with the isRegExp function in a mod js step.

    Any help is appreciated.

    Thanks,
    Andrew

  2. #2
    Join Date
    May 2006
    Posts
    4,882

    Default

    You may have a problem there, in regular expressions it would be something as "\([0-9]\)\1*" for the numbers, but the \( \) doesn't seem to be supported by the java regex.

    Regards,
    Sven

  3. #3
    Join Date
    Feb 2007
    Posts
    21

    Default

    Oh, that's not good.

    Can you explain, or point me to some documentation on, the syntax you described? I haven't seen that before.

    Thanks,
    Andrew

  4. #4
    Join Date
    May 2006
    Posts
    4,882

    Default

    It's not working in Kettle.

    But you first match a single digit and then you say "I want 0 or more times the same one" ... the \1 matches everything between the first \( \) ... works in vi, ... but apparently not in java.

    Regards,
    Sven

  5. #5
    Join Date
    Feb 2007
    Posts
    21

    Default

    Hmmm... Any other suggestions on how I could achieve the same result?

  6. #6
    Join Date
    Feb 2007
    Posts
    21

    Default

    After discovering the terminology used is backreference, and a google search, I think this might work...

    "([a-zA-Z0-9])(\\1)*"

    I'll have a play around tomorrow and see if I can confirm that it is OK.

    Thanks,
    Andrew

  7. #7
    Join Date
    Feb 2007
    Posts
    21

    Default

    Can confirm that this syntax works OK.

    Thanks for your help Sven,

    Andrew

  8. #8
    Join Date
    May 2006
    Posts
    4,882

    Default

    I wrote in one of the previous posts that it's a normal regular epxression, but the java regex doesn't support "backreferences" it seems.

    Regards,
    Sven

  9. #9
    Join Date
    Feb 2007
    Posts
    21

    Default

    Backreferences do seem to be supported by Java. The syntax below works in Java and in the Mod JS step of kettle. The only trick was the double back slash in front of the backreference number. Or am I missing your point?

    Andrew

  10. #10
    Join Date
    May 2006
    Posts
    4,882

    Default

    If it works for you cool

    Regards,
    Sven

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.