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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:05:13+00:00 2026-06-18T02:05:13+00:00

I have a small regular expression to split an integer value into 1000 separated

  • 0

I have a small regular expression to split an integer value into 1000 separated and I was just wondering how it works.

Here’s a perl code.

$intval = 10000;
$intval =~ s/([+-]?\d)(?=(\d{3})+(?!\d))/$1,/go;
print $intval;
  • 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-18T02:05:14+00:00Added an answer on June 18, 2026 at 2:05 am

    (...) Any normal set of parentheses is a capture group that can be referenced after the regex matches, using the special variables $1, $2, etc.

    [+-]? Brackets create a character group, meaning “match any of these characters”. ? means “match zero or one times”. So this allows for the possibility of a single + or – at the beginning of the match.

    \d Match a single digit.

    (?=...) this is a look-ahead. It will require that everything contained in the pattern matches, but not include this in the output “match”. Nor will it move the position in the string forward (this means that matches can overlap when using lookahead).

    (\d{3})+ match one or more groups of three digits.

    (?!\d) the stuff that has matched cannot be followed by another digit.

    /$1,/ Replace what matched (remember, this does not include the lookahead portion because that doesn’t count as part of the match) with the first capture group, followed by a comma.

    go these flags are options setting the regex behavior:

    • g means it repeats until if finds and replaces all matches.
    • o is an optimization telling the interpreter to compile the pattern only once, but it is largely obsolete and makes absolutely no difference in this case since nothing is interpolated into the pattern.

    So this regex will replace a single digit, followed by a number of digits that is a multiple of three, with that digit followed by a comma. It runs repeatedly, finding all matches. The effect of this is to insert commas as thousand separators.

    One quibble: the [+-]? part is completely unnecessary. Because the regex has no requirements about what comes before a number, a number with a + or – will work just fine even if this part is removed.

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

Sidebar

Related Questions

I have small requirement in Regular expression,here I need minimum of one letter of
I started learning regular expression recently. I have a small problem statement now. I
I have absoulutely no experience with regular expressions, so I've run into a small
I have a small piece of code that needs to split a string into
I'm wondering why there have to be so many regular expression dialects. Why does
I have a problem with Regular Expressions. I'm writing a small program that matches
I have small script in bash, which is generating graphs via gnuplot. Everything works
I have a regular expression that I use to grab data between two sets
I have the following regular expression: \[(\d+)\].?\s+(\S+)\s+(\/+?)\\r\n I am pretty new to regex. I
I have created a search and replace program using regular expression for large no

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.