ALERT! The community will be read-only starting on April 19, 8am Pacific as the migration begins. Read more for important details.
ALERT! The community will be read-only starting on April 19, 8am Pacific as the migration begins.Read more for important details.

Using Regex Matches across a Container

Admiral
Admiral
0 0 3,113
0 Likes

Problem



A Forum reader recently asked:

"I have a eDirectory Container with 1000's of Groups. I have a RegEx String to match - *Marketing-Man.* - with the GroupName in that eDirectory Container in order to get the DN for a matched Group.

I want to traverse all the Groups in a specified eDirectory Container one by one, and perform a RegEx match operation on the current Group."

And here is the response from Father Ramon ...

Solution



If your regular expression is a simple one, you could just do a query on CN using wildcard character "*" and then loop on it. For example:


<do-for-each>
<arg-node-set>
<token-query class-name="Group" datastore="src" scope="subordinates">
<arg-dn>
<token-text>org\mygroups</token-text>
</arg-dn>
<arg-match-attr name="CN"/>
</token-query>
</arg-node-set>
<arg-actions>
<do-set-local-variable name="current-group-dn" scope="policy">
<arg-string>
<token-xpath expression="$current-node/@src-dn"/>
</arg-string>
</do-set-local-variable>
<do-trace-message>
<arg-string>
<token-text xml:space="preserve">Processing group: </token-text>
<token-local-variable name="current-group-dn"/>
</arg-string>
</do-trace-message>
</arg-actions>
</do-for-each>



If you really do need a real regular expression, then it is only slightly more complicated:


<do-for-each>
<arg-node-set>
<token-query class-name="Group" datastore="src" scope="subordinates">
<arg-dn>
<token-text>org\mygroups</token-text>
</arg-dn>
<arg-match-attr name="CN"/>
</token-query>
</arg-node-set>
<arg-actions>
<do-set-local-variable name="current-group-dn" scope="policy">
<arg-string>
<token-xpath expression="$current-node/@src-dn"/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="current-group-name" scope="policy">
<arg-string>
<token-parse-dn length="1" start="-1"/>
<token-local-variable name="current-group-dn"/>
</arg-string>
</do-set-local-variable>
<do-if>
<arg-conditions>
<and>
<if-local-variable mode="regex" name="current-group-name"
op="equal"><same fancy regular expression></if-local-variable>
</and>
</arg-conditions>
<arg-actions>
<do-trace-message>
<arg-string>
<token-text xml:space="preserve">Processing group: </token-text>
<token-local-variable name="current-group-dn"/>
</arg-string>
</do-trace-message>
</arg-actions>
<arg-actions/>
</do-if>
</arg-actions>
</do-for-each>

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.