Workflow - Compare complex string

Hello,

Is there a way to make a complex string comparison with workflows ?
I’m trying to check if a string has the format “word1 XXX word2” where “XXX” is a variable string.

Thanks !

Hi @timahm ! I think you can do it with the Define Variable Operator combined later with the Compare String. I tried this example and actually works, perhaps you should only work more on the pattern box of the last define variable.

This is my structure (trigger is only for testing purposes, and certainly you should get variables from other context):

First define variable is only to set the 3 variables you mentioned (word1, word2 and XXX):

Next define variable only joins these three variables:

Define Variable 3 (I used a DV2 but deleted it later), is the one that evaluates regular expression. It replace the “Word1 XXX Word2” String with the “ISOK” fixed String. So, always that the pattern is matched, the Define Variable 3 operator will return ISOK. Otherwise, it will return the result from Define Variable1:

Is on the pattern box that you perhaps should to work a little more than this:

Finally, I use Compare Stirngs operator, to test if Define Variable 3 output is “ISOK” (meaning that original variable matches pattern), or is not:

For example, letting first 3 variables be Word1, XXX and Word2:

Compounding last 3 variables:

Regex evaluates to “ISOK”:

Now suppose I change received XXX variable to YYY:

When testing, pattern evaluation will cause to continue on the FALSE exit:

Notice that the REGEX Defined Variable, as the patter is not matched, it returns original String:

And as it is not the “ISOK” String, that is why it goes on the FALSE exit path.

Hope it works!

1 Like

Hello @jsosa
Thank you so much for your time and your feedback.
However, I’m not sure this could help for the context. Indeed, after getting roles (by Http Request), I’m using a loop to check if roles have assigned identities. I want to exclude some roles from the check and the format role names is “word1 XXX word2”.
“word1” and “word2” are the same for all the roles.

One solution is to use the compare strings and specify all the ids (I want to avoid it since I have more than 100 roles).

Thank you so much.

My pleasure! Does the XXX part of unwanted entitlements have some pattern? Remember that the regex Define Variable pattern box support full regular expression.

For example, pattern
word1\s[^\s-]+\sword2

Should match
word1 xxx word2
wors1 yyy word2
word1 otherword word2
word1 anynonwhitespace word2

and then you can replace all pattern wih SOMESTRING, and use the comparator as I showed.

I think major problem is to find something in common of all these unwanted entitlements and try to put it in a regex expression, in the place where I put [^\s-]+ earlier (rest of pattern should remain the same)

1 Like

Thank you so much @jsosa for your help :slight_smile: It works !
Indeed, the part XXX is a country or city wich is defined as a membership criteria (They don’t have the same json path for all unwanted roles. Otherwise, I could put it in the variable and use it for filtering).

Thanks you Tima! Grest it worked, have a happy new year!

1 Like

Thank you Julian ! Happy new year with best wishes !

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.