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 7951381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:32:33+00:00 2026-06-04T02:32:33+00:00

I know how to strip out extra spaces, dashes, and periods using preg_replace(), but

  • 0

I know how to strip out extra spaces, dashes, and periods using preg_replace(), but I need to know what format below is correct for stripping out extra asterisks in a string.

These lines of code work for stripping out extra spaces, dashes, and periods:

// Strips out extra spaces
   $string = preg_replace('/\s\s+/', ' ',$string);
// Strips out extra dashes
   $string = preg_replace('/-+/', '-', $string);
// Strips out extra periods
   $string = preg_replace('/\.+/', '.', $string);

Which of the following is correct for stripping out extra asterisks?

// Version 1: Strips out extra asterisks
   $string = preg_replace('/\*+/', '*', $string);

// Version 2: Strips out extra asterisks
   $string = preg_replace('/*+/', '*', $string);

Thank you in advance.

By the way, is there a list somewhere that shows all the characters that need to be escaped with a forward slash when using PHP?

  • 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-06-04T02:32:35+00:00Added an answer on June 4, 2026 at 2:32 am

    Try this:

    $string = preg_replace('/\*{2,}/', '*', $string);
    

    This will replace any instances of multiple asterisks next to one another with one asterisk.

    Or, if you wanted to just get rid of all asterisks:

    $string = preg_replace('/[\*]+/', '', $string);
    

    It’s worth noting that * is a special character in regular expressions; so, you must escape it with a backslash.

    Also, here’s a good regex reference:
    http://www.regular-expressions.info/reference.html

    Here’s how you could combine multiple character replacements into one regex:

    $string = preg_replace('/(\*|\.){2,}/', '$1', $string);
    

    This will replace asterisks as well as periods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that browsers strip out extra spaces after a single space. I generally
Know this might be rather basic, but I been trying to figure out how
I am doing a query where I need to strip out some lower-level results
I know I've seen this done a lot in places, but I need something
In Ruby, what regex will strip out all but a desired string if present
I need to strip HTML out of large volumes of text. It would be
I know there are similar questions out there, but I'm having trouble with this
I know using a regex to parse html is normally a non-starter but I
just.... don't know why two strip slash function.
How can i strip <h1>including this content</h1> I know you can use strip tags

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.