Working with regex

Hi together,

while importing my computerobjects from AD, i want to extract a string between two brackets to use this for another Variable. Unfortunately, my regex doesnt work and i have no idea why.

This is my regex: ([(.*?)])
This is a example string: [FS] Fileserver (Windows)
Method is: RegexSplit

I want to extract the string ‘FS’ between the square brackets.

Does somebody has any idea?

Regards,
Robert

RegexSplit is the wrong modifier (splitting into an array using regex), use Regular Expression based replacement instead.
As Regex use /\[(.*)\].*/ which is everything between the brackets in capture group 1 but matches everything.
As Replacement use \1 so it replaces everything with the capture group 1.

1 Like

Hi Dirk,

Fantastic, it works. Now i have to filter Objects without brackets, like this one: “RD-Lizenzserver”.
Can the first regex be expanded or should i create a second modification-rule with regex-split?

Regards,
Robert

Depends on what you exactly need.

My try would be an or-clause /\[(.*)\].*|.*/. This will match everything when there are no brackets in the or-clause and then capture group 1 should be empty, so my hope would be it would replace everything with an empty string.

Would the empty string be ok? If not and null is needed, it gets tricky as you would need to import values in a datalist and use map as modifier.

1 Like

Hi Dirk,

I filter out the empty String with (^[0-9]*$|^NULL$). Now everythink works fine.

Thank you.

Kind regards
Robert