sma2006 Outstanding Contributor.
Outstanding Contributor.
234 views

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
Labels (1)
0 Likes
4 Replies
Knowledge Partner
Knowledge Partner

Re: How to apply regex expression to variable in IDM rule

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.
0 Likes
Knowledge Partner
Knowledge Partner

Re: How to apply regex expression to variable in IDM rule

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.)
______________________________________________
https://www.is4it.de/identity-access-management
0 Likes
sma2006 Outstanding Contributor.
Outstanding Contributor.

Re: How to apply regex expression to variable in IDM rule

Yes, this is exactly what I did.
Works fine.
Thx
0 Likes
Knowledge Partner
Knowledge Partner

Re: How to apply regex expression to variable in IDM rule

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;
}
}




0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.