# irule help

**URL:** <https://community.f5.com/t/irule-help/47536>\
**Category:** Technical Forums\
**Tags:** ltm, application-delivery\
**Created:** [June 18, 2018, 3:12am UTC](https://community.f5.com/t/irule-help/47536 "2018-06-18T03:12:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![F5-Geek](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@F5-Geek](https://community.f5.com/u/F5-Geek)\
**Post date:** [June 18, 2018, 3:12am UTC](https://community.f5.com/t/irule-help/47536/1 "2018-06-18T03:12:16Z")

</div>

I would like convert the email address into username. for example email address [Jack.White001@acme.com](mailto:Jack.White001@acme.com) to username jwhit001

---

<div class="post-metadata">

**Author:** ![Edward\_Gastón\_S](https://avatars.discourse-cdn.com/v4/letter/e/f08c70/32.png) [@Edward\_Gastón\_S](https://community.f5.com/u/Edward_Gast%C3%B3n_S)\
**Post date:** [June 18, 2018, 3:43am UTC](https://community.f5.com/t/irule-help/47536/2 "2018-06-18T03:43:17Z")

</div>

Hello Innovator,

what is the motive or reason for change name?, can you prove more information of the that you need, please

---

<div class="post-metadata">

**Author:** ![crodriguez](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@crodriguez](https://community.f5.com/u/crodriguez)\
**Post date:** [June 18, 2018, 4:01am UTC](https://community.f5.com/t/irule-help/47536/3 "2018-06-18T04:01:05Z")

</div>

I think what Edward is asking for are the specifications for the conversion. In your example, it looks like you pull the first character of the email address part that appears before the dot, followed by the first four characters of the part that appears after the dot, followed by the numbers that appear at the end of the part after the second dot. But is it always this way? Are there always a static number of digits in the email address (3), or is it variable? In other words, to do this programmatically, such as with an iRule, we have to know the rules for transformation.

---

<div class="post-metadata">

**Author:** ![F5-Geek](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@F5-Geek](https://community.f5.com/u/F5-Geek)\
**Post date:** [June 18, 2018, 4:21am UTC](https://community.f5.com/t/irule-help/47536/4 "2018-06-18T04:21:54Z")

</div>

thanks for reply, this email address which we get the email address of the UPN, but the back only knows the username , we want to convert the email address in username send to the backend server yes,jwhit001, username would always be in this format first letter from the firstname then four letters from the lastname and ends with three digits

---

<div class="post-metadata">

**Author:** ![youssef1](https://avatars.discourse-cdn.com/v4/letter/y/ed655f/32.png) [@youssef1](https://community.f5.com/u/youssef1)\
**Post date:** [June 18, 2018, 1:15pm UTC](https://community.f5.com/t/irule-help/47536/5 "2018-06-18T13:15:41Z")

</div>

Hi,

i write you this irule:

```tcl
when HTTP_REQUEST {

set mail "youssef.brown@mydomain.com"

regexp {^(.{0,1})[^.]+.([^@]+)} $mail -> firletername lastname

set username "$firletername$lastname"

log local0. "USERNAME: $username"

 you will receive this logs USERNAME: ybrown

}

```

If you give me the context (if you use APM or not) I can give you more details. keep me in touch

Regards

---

<div class="post-metadata">

**Author:** ![stan\_piron](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@stan\_piron](https://community.f5.com/u/stan_piron)\
**Post date:** [June 19, 2018, 6:55am UTC](https://community.f5.com/t/irule-help/47536/6 "2018-06-19T06:55:24Z")

</div>

Hi,

In such case, I request AD server with UPN and retrieve AD sAMAccountName.

First, replace this irule to a variable assign like in [this link](https://devcentral.f5.com/codeshare/apm-variable-assign-examples-1107?tag=apm%3bvariable+assign). the following code extract without the irule event.

```tcl
set extension [string tolower [mcget {session.ssl.cert.x509extension}]];  
return [string range $extension [expr {[string first "othername:ups<" $extension] +14}] [expr {[string last ">" $extension] -1}] ];

```

after this, add a AD query box with Filter:

```tcl
(userPrincipalName=%{session.logon.last.upn})

```

then sAMAccountName is store in session.ad.last.attr.sAMAccountName. you can copy it in **session.logon.last.username** with a new variable assign box with expression.

```tcl
expr {[mcget {session.ad.last.attr.sAMAccountName}]}

```

don’t forget to create 2 variables:

- session.logon.last.username
- session.logon.last.logonname (used in active session or event logs)

**Note:** Variable assign code change. there was an issue with string first searching for an uppercase string in a lowercase converted string.
