Regular expression

Using the correct expression and replacement using the widespread regular expressions language, you should be able to transform usernames as long as they follow some consequent pattern. If your incoming username is john.doe_teacher@example.com and you would like to have it converted to john.doe@example.com, a regular expression could help you solve this.

One way of doing this is dividing the incoming username into groups by using this expression:

(.*)(_)(.*)(@)(.*)

Here:

  • the parentheses are creating the groups

  • period "." indicates any symbol

  • star "*" means from 0 to many occurrences of the preceding symbol

The five groups can then be used as the replacement to create the new username. Each group is getting a numeral, incremental name where their name and value in the given example would be:

  • $1 = "jon.doe"

  • $2 = "_"

  • $3 = "teacher"

  • $4 = "@"

  • $5 "example.com"

To create a new username as an output, use the variables and other symbols to build the replacement. In the given example, having the replacement set to $1$4$5 will transform from john.doe_teacher@example.com to john.doe@example.com.

Change case of username

When using just-in-time provisioning and regular expressions for username lookup, you may want to control what case usernames get. By using \L (lowercase) and \U (uppercase) in front of $1 and other replacements (see above examples), you may instruct what case the username for the newly created user will be.

So for example, if you want the domain to have uppercase for created usernames, use the expression:

(.*)@(.*)

and then instruct all after @ symbol to be uppercase with this replacement:

$1@\U$2

Performing case-insensitive searches

By adding (?i) in the beginning of your transformation you will get case-insensitive searches. So if your transformation is (?i)(.*)@example.com this will both match all case versions of the domain name like john.doe@example.com, john.doe@Example.Com and john.doe@EXAMPLE.COM.

See more details on the language of regular expressions here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

You may also build and test regex matches here:

https://regex101.com/