Writing regular expressions
By 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 sort of consequent pattern. If for example
your incoming username is:
john.doe_teacher@example.com
and you would like to have it transformed 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 occurences
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
See more details on the language of regular expressions here:
https://www.w3schools.com/jsref/jsref_obj_regexp.asp