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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:31:16+00:00 2026-06-17T10:31:16+00:00

I use preg replace to separate numbers by inserting a space between each group

  • 0

I use preg replace to separate numbers by inserting a space between each group of three digits:

$alexa_rank_raw = 8389876;

$alexa_rank = preg_replace("/(\d{3})/", '$1.', $alexa_rank_raw);

// alexa rank becomes: 838.987.6

How can I do the replace so the final number would look like this:

8.389.876

Any ideas?

  • 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-17T10:31:17+00:00Added an answer on June 17, 2026 at 10:31 am

    You are looking for number_format.

    $rank = number_format($alexa_rank_raw, 0, ",", ".");
    

    But here’s also a regex version, because why not?

    $rank = preg_replace('/(\d{1,3})(?=(\d{3})+$)/', '$1.', $alexa_rank_raw);
    

    How it works: it matches groups of up to three digits greedily (as many as possible up to three), but uses positive lookahead to assert that there is an exact multiple of three digits starting from the position where the matched group ends all the way up to the end of the input.

    See it in action.

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

Sidebar

Related Questions

What I want to do is use preg replace to replace matches within a
I'm busy with a website and for an element I use preg_replace to replace
Can you use two regex in preg_replace to match and replace items in an
I'm trying to use preg_replace to replace &lt;a href=&quot;WWW.ANYURL.COM&quot;&gt;DISPLAY_TEXT&lt;/a&gt; with <a href=WWW.ANYURL.COM>DISPLAY_TEXT</a> here is
How to use preg_replace() for change all space that is not within < >
I need to strip unwanted characters from a string. I want to use preg
I want to use preg_replace_callback to replace all instances of a custom tag with
How can I use preg_replace to do this: I want to replace: <a href=index.php?option=example1&view=something>
I am looking for a solution where I can use preg_replace to replace certain
Possible Duplicate: Regex / Preg: No match, if found I want to use preg_replace

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.