How to apply regex expression to variable in IDM rule

Hello,
I'm sure I did it before, but cannot find this in my files.

I have a local variable that contain an error message like : "USER ERROR : password for user XTEST error"

And I want to get the username with the following regex : (?<=password for user ).{1,8}

(I don't have any reference to the user CN or association in the error status message)

The regex works fine, but I don't know how to apply the regex directly to the variable ?

Probably in XPATH expression ?


Thanks

Sylvain
  • Doesn't the replace-all token let you use capturing groups from the Java
    Pattern/Matcher classes? I'd try that, or if not that, just replace
    everything that you know will be there other than the usrename, which
    looks like a couple static strings.



    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below.

    If you want to send me a private message, please let me know in the
    forum as I do not use the web interface often.
  • On 5/22/2019 8:56 AM, sma wrote:
    >
    > Hello,
    > I'm sure I did it before, but cannot find this in my files.
    >
    > I have a local variable that contain an error message like : "USER ERROR
    > : password for user XTEST error"
    >
    > And I want to get the username with the following regex : (?<=password
    > for user ).{1,8}
    >
    > (I don't have any reference to the user CN or association in the error
    > status message)
    >
    > The regex works fine, but I don't know how to apply the regex directly
    > to the variable ?
    >
    > Probably in XPATH expression ?


    You could use:
    If local variable equal Regex to find out if it is there.

    Or use ECMA like this:

    function showmatch(s1,s2)
    {
    // Build search and replace options. i=case insensitve mode, s=single
    line mode, m=multiline mode, x=free space mode
    // See this page for these options:
    http://www.regular-expressions.info/modifiers.html
    var options = "i";

    var re = new RegExp(s2, options);
    var m = re.exec(s1)
    if (m !==null) {
    return m.toString();
    } else {
    return false;
    }
    }




  • ab wrote:

    > Doesn't the replace-all token let you use capturing groups from the Java
    > Pattern/Matcher classes?


    Yes it does:

    Test : token-replace-first(".*USER ERROR: password for user (. ?)
    error.*","$1",token-local-variable("errormessage"))
    Test : token-local-variable("errormessage")
    Test : Token Value: "USER ERROR: password for user XTEST error".
    Test : Token Value: "XTEST".

    and with a little tweak, the initial lookbehind version also works:

    Test : token-replace-first(".*(?<=password for user
    )(\w{1,8}).*","$1",token-local-variable("errormessage"))
    Test : token-local-variable("errormessage")
    Test : Token Value: "USER ERROR: password for user XTEST error".
    Test : Token Value: "XTEST".


    --
    http://www.is4it.de/en/solution/identity-access-management/

    (If you find this post helpful, please click on the star below.)
  • Yes, this is exactly what I did.
    Works fine.
    Thx