Search code examples
.netregexnintex-workflow

Using RegEx to extract Office 365 email UPN formatted


I am using the .NET regex syntax in a Nintex action and would like to extract the email as shown below

i:0#.f|membership|daniel.Smith@domain.onmicrosoft.com

Now I think the approach is match the i:0#.f|membership bit but exclude it then match the rest. I would appreciate any help on this. I did try this expression which did match some on the above.

(?<=)(i:0#.f|membership).

Daniel


Solution

  • If you plan to use the Extract mode with Nintex, you may use

    [^|]+$
    

    to match 1 or more characters other than | that are at the end of the string. The [^...] is called a negated character class that contains literal symbols or ranges that are NOT to be matched, and everything else gets matched:

    The result is that the [negated] character class matches any character that is not in the character class.

    See the regex demo

    Alternatively, you might use a replace action with

    ^.*\|
    

    and replace with empty text. See this demo.

    The point here is that we first match the string start and then use backtracking with a greedy dot (.*) to get to the last literal |, and remove the whole match.