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

  • Home
  • SEARCH
  • 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 6702523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:03:50+00:00 2026-05-26T07:03:50+00:00

I want to find any pattern matching: ###-##-#### and replace the ###-##, with ***-**

  • 0

I want to find any pattern matching: ###-##-####

and replace the ###-##, with ***-**

but leave the -####

I tried this below, but nothing is being replaced at all.

preg_replace('/(^[\d]{3})(-)([\d]{2})(-[\d]{4}$)/','\2\4',$myText);

Any help is appreciated


Update, here is my entire code string as it currently stands, after trying a few of the suggestions below. I am comparing the second echo output to the first… and the social numbers all remain the same.

Also, as it was mentioned below, my string does contain more than just a social… it is thousands of characters long. which i think is my real issue. Sorry if i didnt clear that up in the beginning.

    //Make the CSC credit report request.
    $strCscResponse = $Csc->makeRequest($strFixedFormatRecord);

    echo "<br/><br/><pre>" . $strCscResponse  . "</pre><br/><br/>";

    $strCscResponse = str_replace("!", " ", $strCscResponse);

    $strCscResponse = preg_replace('/^\d{3}-\d{2}(-\d{4})$/','***-**$1',$strCscResponse);

    echo "<br/><br/><pre>" . $strCscResponse  . "</pre><br/><br/>";

update

I’d like to mark all the answers and “the answer” just because i didnt clarify the string has more than just a social in it. thank you for the help with this issue, embarrisingly enough it has been driving me wild for a couple days now.

  • 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-26T07:03:50+00:00Added an answer on May 26, 2026 at 7:03 am

    There is one possible problem: you might not be matching the right string (if you are trying to find SSNs buried in a large block of text) – the ^ and $ anchors will only match beginning of string (or sometimes beginning of line) – if this is not what you want, but instead you want to find SSNs in a long string, you need to get rid of those anchors.

    The other problem, potentially, is that you seem to want to replace things with asterisks, but you do not include asterisks in your replacement expression. you need to use a replacement expression like

    `***-**\4`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I find myself using the 'pattern' below rather unsettlingly often, when I want to
I want to find any text in a file that matches a regexp of
I dont know if it is asked (I couldn't find any). I want to
I want to find whether a string contains any of the special characters like
I want to quickly find the total size of any folder using python. import
I want to find out all the subdomains of a given domain. I found
I want to find a sql command or something that can do this where
This page has a great example using REGEXP to do pattern matching. The problem
I'm using Sybase 12.5.3, and want/need to do regex pattern matching. The Sybase help
i want to find whether a particular pattern exists in my text file or

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.