Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6210433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:09:30+00:00 2026-05-24T06:09:30+00:00

How to mask SSN in a string ? I am have the following scenario

  • 0

How to mask SSN in a string ?

I am have the following scenario

string str1 = "asdasfasdfasdf sfhagfdad SSN:123456789";

my required output "asdasfasdfasdf sfhagfdad SSN:*********"

I tried the below code

Regex ssnRegex = new Regex("(?:\bSSN:\b)(?:[0-9]{3})(?:[0-9]{2})(?:[0-9]{4})");
string formattedSSN = ssnRegex.Replace(t1, "SSN:-XXX-XX-XXXX");

I think i am missing to capture “SSN:” Could you please tell me how to get the above output

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:09:30+00:00Added an answer on May 24, 2026 at 6:09 am

    Why not just use String.Replace?

    string str1 = "asdasfasdfasdf sfhagfdad SSN:123456789";
    
    //Get starting position
    int position = str1.IndexOf("SSN:") + 4;
    
    //Extract social
    string ssn = str1.Substring(position, 9);
    
    //Update string
    str1 = str1.Replace(ssn, "XXX-XX-XXXX");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I apply a mask to a string aiming to format the output
I have mask in textbox 99:99 I need convert to decimal. example: string 12:34
I have a JFormattedTextField using the following mask formatter: private MaskFormatter maskForInput; maskForInput=new MaskFormatter(####);
I have a bit-mask of N chars in size, which is statically known (i.e.
I want to mask all the characters of a string except the first and
C# locale-aware MaskedTextBox mask for DateTime values I'm working through FXCop/Code Analysis's Globalization warnings
I hope to mask the text input to UITextField as: ABCDE to ***** below
I mask the input of fields like SSN to contain dashes when they are
How can create a mask input for number that have percent by jQuery? Do
How to mask a password from console input? I'm using Java 6. I've tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.