Jump to content

Regex Substring automation questions


Andrew McAllister

Recommended Posts

Question 1) What should I be putting into the Co-worker option, if it is set to expect a variable, on an Add Connection automation? Note not the co-worker (from variable) option. I know this needs UerId

I have tried the handle as this is what is shown when set to manual but that fails with an undefined user

I have tried using regex to extract the employeeID from our handle and not had much joy. Our handles are imported via LDAP in the form FirstName LastName (EmployeeID) so need to pull out the contents of the brackets, however some users have brackets in the LastName (out of my control) so I actually need to pull out the contents of the last set of brackets and feed that through.

So Andrew McAllister (AMcAllister) should return AMcAllister.

Andrew McAllister (Contractor) (AMcAllister) should also return AMcAllister.

I have got as far as getting a regex string that seems to work on Regex101

.*\(\K[^\)]*

but again when I then try to use the result from the regex operation to set the co-worker it fails with an undefined user. When I wrote the outcome to the timeline the regex outcome was failed, so clearly no result and therefore the add connection failed.

Is there a better way of capturing, during self service, if this is for customer logging the ticket and if not adding the affected user as an impacted user.

Question 2) I have been testing this by using update Timeline to print the regex outcome and result, Is there an easier way of troubleshooting? As the troubleshooting nodes will need to be removed before publishing.

Question 3) When I was testing things on Regex101 it was returning a group and a match, is there a way of accessing the group result in the regex Substring automation or do I need to get the result I need from the match?

Question 4) Are there aspects of regex that are unsupported by the automation such as returning the groups mentioned above?

Link to comment
Share on other sites

For the regex side: I don't think you can access the group result using the Hornbill function, but there is a (unsupported) work around.

Rather than using a function, you can put the regex directly into the variable, for example:

&[global["flowcoderefs"]["whatever"]["variable"].match(/REGEX HERE/)[1]]

Be careful with the placement of the square brackets.

Try out the following regex for what you want to achieve (not tested extensively) - it should match the contents of the last brackets in a string:

/\(([^()]+)\)[^()]*$/

 

Link to comment
Share on other sites

Thanks for the tip on the work around. If I understand correctly the .match (whatever)[1] returns the group contents?

However the regex string I have seems to return a match result without the need for the unsupported group stuff. Hence my other questions about what other parts of regex may or may not be supported and how I can troubleshoot more easily.

.*\(\K[^\)]*

 

Link to comment
Share on other sites

10 minutes ago, Andrew McAllister said:

Thanks for the tip on the work around. If I understand correctly the .match (whatever)[1] returns the group contents?

However the regex string I have seems to return a match result without the need for the unsupported group stuff. Hence my other questions about what other parts of regex may or may not be supported and how I can troubleshoot more easily.

.*\(\K[^\)]*

 

This won't work because it's not supported by the regex engine JavaScript uses. You'll need to use capturing groups similar to the regex example I gave.

Link to comment
Share on other sites

8 minutes ago, Met said:

This won't work because it's not supported by the regex engine JavaScript uses. You'll need to use capturing groups similar to the regex example I gave.

Boo!!, and I felt so clever when I got it working in Regex101.

 

Is there documentation of what is/is not supported for use in Hornbill?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...