Ensign
Ensign
486 views

argument builder regex

Jump to solution

Hello Expert 


I want to set my CN using username from email address 

example 

i have email address 'jhon.doe' @sample.mail and I want to set my cn become jhon.doe 

how to do that 

thanks for help 

Cheers

1 Solution

Accepted Solutions
Knowledge Partner Knowledge Partner
Knowledge Partner
Norbert's version:

<do-set-local-variable name="lvSMTP" scope="policy">
<arg-string>
<token-text xml:space="preserve">jhon.doe@sample.mail</token-text>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="lvCN" scope="policy">
<arg-string>
<token-replace-first regex="@.*" replace-with="">
<token-local-variable name="lvSMTP"/>
</token-replace-first>
</arg-string>
</do-set-local-variable>

Simulation:
test : Applying rule 'lvSMTP'.
test : Action: do-set-local-variable("lvSMTP",scope="policy","jhon.doe@sample.mail").
test : arg-string("jhon.doe@sample.mail")
test : token-text("jhon.doe@sample.mail")
test : Arg Value: "jhon.doe@sample.mail".
test : Action: do-set-local-variable("lvCN",scope="policy",token-replace-first("@.*","",token-local-variable("lvSMTP"))).
test : arg-string(token-replace-first("@.*","",token-local-variable("lvSMTP")))
test : token-replace-first("@.*","",token-local-variable("lvSMTP"))
test : token-replace-first("@.*","",token-local-variable("lvSMTP"))
test : token-local-variable("lvSMTP")
test : Token Value: "jhon.doe@sample.mail".
test : Arg Value: "jhon.doe@sample.mail".
test : Token Value: "jhon.doe".
test : Arg Value: "jhon.doe".

View solution in original post

5 Replies
Micro Focus Expert
Micro Focus Expert

You can do a replace-first with a regex like

@.*

https://regex101.com/ is a great site for testing your patterns.

--
Norbert
Ensign
Ensign

Hi @klasen 

Would you advice me how to achieve that, and which policy configuration should i configure

Thanks  

0 Likes
Knowledge Partner Knowledge Partner
Knowledge Partner
Norbert's version:

<do-set-local-variable name="lvSMTP" scope="policy">
<arg-string>
<token-text xml:space="preserve">jhon.doe@sample.mail</token-text>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="lvCN" scope="policy">
<arg-string>
<token-replace-first regex="@.*" replace-with="">
<token-local-variable name="lvSMTP"/>
</token-replace-first>
</arg-string>
</do-set-local-variable>

Simulation:
test : Applying rule 'lvSMTP'.
test : Action: do-set-local-variable("lvSMTP",scope="policy","jhon.doe@sample.mail").
test : arg-string("jhon.doe@sample.mail")
test : token-text("jhon.doe@sample.mail")
test : Arg Value: "jhon.doe@sample.mail".
test : Action: do-set-local-variable("lvCN",scope="policy",token-replace-first("@.*","",token-local-variable("lvSMTP"))).
test : arg-string(token-replace-first("@.*","",token-local-variable("lvSMTP")))
test : token-replace-first("@.*","",token-local-variable("lvSMTP"))
test : token-replace-first("@.*","",token-local-variable("lvSMTP"))
test : token-local-variable("lvSMTP")
test : Token Value: "jhon.doe@sample.mail".
test : Arg Value: "jhon.doe@sample.mail".
test : Token Value: "jhon.doe".
test : Arg Value: "jhon.doe".

View solution in original post

Knowledge Partner Knowledge Partner
Knowledge Partner
Another simple option: use built-in XPATH function substring-before.

<do-set-local-variable name="lvCN" scope="policy">
<arg-string>
<token-xpath expression="substring-before($lvSMTP,'@')"/>
</arg-string>
</do-set-local-variable>

Simulation:
test : Applying rule 'lvSMTP'.
test : Action: do-set-local-variable("lvSMTP",scope="policy","jhon.doe@sample.mail").
test : arg-string("jhon.doe@sample.mail")
test : token-text("jhon.doe@sample.mail")
test : Arg Value: "jhon.doe@sample.mail".
test : Action: do-set-local-variable("lvCN",scope="policy",token-xpath("substring-before($lvSMTP,'@')")).
test : arg-string(token-xpath("substring-before($lvSMTP,'@')"))
test : token-xpath("substring-before($lvSMTP,'@')")
test : Token Value: "jhon.doe".
test : Arg Value: "jhon.doe".

and many other options available.
🙂
Ensign
Ensign

Thanks @al_b 
that help me alot 😁

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.