Regex to find SSN and Phone number only

Need regex pattern to find the flowing:

  1. Social security Number
  2. phone number

→ I have used “(?<=social security number )(-| |\d)+” However, it is finding all the number patterns.

Need regex pattern to find only in SSN pattern(with and without -) and phone number (with and without country code).

@Arun_Singh
give us a sample

Hi @Arun_Singh ,

Could you maybe provide us with Sample data for us to understand the pattern and the expression that we could use ?

Hello @Arun_Singh, Kindly share the spme sample inputs.
Try this

(?<=social security number*?)[\d\W]+

Hi @Arun_Singh

Can you share the sample input?

How about this regex expression?

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=Social security Number)-\d+|\s\d+").Tostring

image

Regards
Gokul

Thanks for the replies, However I don’t have any samples as I’m trying to integrate with ChatGPT using input dialog box, when user ask the questions in input dialog box and BOT will validate the question- if SSN or Phone number pattern is available in the question, the BOT should say don’t share your SSN or phone number to ChatGPT before it passes the HTTP request.

To find only Social Security Numbers and phone numbers, you can use the following regex patterns:

  1. Social Security Number (SSN) pattern:
  • With dashes: \b\d{3}-\d{2}-\d{4}\b
  • Without dashes: \b\d{9}\b
  1. Phone number pattern (with and without country code):
  • With country code (e.g., +1): (?<!\d)\+\d{1,3}-\d{3}-\d{3}-\d{4}\b
  • Without country code: \b\d{3}-\d{3}-\d{4}\b

Make sure to use the appropriate pattern depending on the type of information you are searching for.