How to remove a space in a first name

Juan-Carlos Cardenas 0 Reputation points
2025-02-22T19:01:40.7866667+00:00

Hello,

   I have a user who has a space in their first name and it is causing issues with the vendor that is receiving the first name attribute from Microsoft Entra.  The vendor also requires a custom attribute that brings the first name and last name together but separated by a "."  What is the best way that I can remove that space in the first name when sending the SAML assertion to the vendor?  Does this require a Regex Replace function?  If so, what would the Regex be?  

Current:
firstname SAML user.givenname Ex: John Charles

SSOID SAML Join (user.givenname, ".", user.surname) Ex: John Charles.Jones

Vendor needs:

firstname SAML user.givenname Ex: JohnCharles

SSOID SAML Join (user.givenname, ".", user.surname) Ex: JohnCharles.Jones

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
23,340 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marcin Policht 36,435 Reputation points MVP
    2025-02-22T20:31:21.9966667+00:00

    To address the issue where the first name includes a space and the vendor requires it to be formatted without that space, you can indeed use a regex to remove the space from the first name before sending the SAML assertion. For example, in Python, you can use the re.sub() method to apply this regex.

    You need a regular expression that matches spaces in the first name and replaces them with an empty string. After cleaning up the first name, you can join the first name and surname as required.

    To implement it, you can use the regular expression \s+ which matches one or more whitespace characters (including spaces). You will use this regex in combination with joining the first name and surname.

    Here is sample code:

    import re
    
    # Sample values for first name and last name
    first_name = "John Charles"
    last_name = "Jones"
    
    # Step 1: Remove the space in the first name
    cleaned_first_name = re.sub(r'\s+', '', first_name)  # This will remove all spaces
    
    # Step 2: Create the combined SSOID value
    ssoid = f"{cleaned_first_name}.{last_name}"
    
    # Results
    print(f"Cleaned First Name: {cleaned_first_name}")  # Output: JohnCharles
    print(f"SSOID: {ssoid}")  # Output: JohnCharles.Jones
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.