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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:42:13+00:00 2026-05-12T09:42:13+00:00

I need a regex to get numeric values that can be 111.111,11 111,111.11 111,111

  • 0

I need a regex to get numeric values that can be

111.111,11

111,111.11

111,111

And separate the integer and decimal portions so I can store in a DB with the correct syntax

I tried ([0-9]{1,3}[,.]?)+([,.][0-9]{2})? With no success since it doesn’t detect the second part 🙁

The result should look like:

111.111,11 -> $1 = 111111; $2 = 11
  • 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-12T09:42:13+00:00Added an answer on May 12, 2026 at 9:42 am

    First Answer:

    This matches #,###,##0.00:

    ^[+-]?[0-9]{1,3}(?:\,?[0-9]{3})*(?:\.[0-9]{2})?$
    

    And this matches #.###.##0,00:

    ^[+-]?[0-9]{1,3}(?:\.?[0-9]{3})*(?:\,[0-9]{2})?$
    

    Joining the two (there are smarter/shorter ways to write it, but it works):

    (?:^[+-]?[0-9]{1,3}(?:\,?[0-9]{3})*(?:\.[0-9]{2})?$)
    |(?:^[+-]?[0-9]{1,3}(?:\.?[0-9]{3})*(?:\,[0-9]{2})?$)
    

    You can also, add a capturing group to the last comma (or dot) to check which one was used.


    Second Answer:

    As pointed by Alan M, my previous solution could fail to reject a value like 11,111111.00 where a comma is missing, but the other isn’t. After some tests I reached the following regex that avoids this problem:

    ^[+-]?[0-9]{1,3}
    (?:(?<comma>\,?)[0-9]{3})?
    (?:\k<comma>[0-9]{3})*
    (?:\.[0-9]{2})?$
    

    This deserves some explanation:

    • ^[+-]?[0-9]{1,3} matches the first (1 to 3) digits;

    • (?:(?<comma>\,?)[0-9]{3})? matches on optional comma followed by more 3 digits, and captures the comma (or the inexistence of one) in a group called ‘comma’;

    • (?:\k<comma>[0-9]{3})* matches zero-to-any repetitions of the comma used before (if any) followed by 3 digits;

    • (?:\.[0-9]{2})?$ matches optional “cents” at the end of the string.

    Of course, that will only cover #,###,##0.00 (not #.###.##0,00), but you can always join the regexes like I did above.


    Final Answer:

    Now, a complete solution. Indentations and line breaks are there for readability only.

    ^[+-]?[0-9]{1,3}
    (?:
        (?:\,[0-9]{3})*
        (?:.[0-9]{2})?
    |
        (?:\.[0-9]{3})*
        (?:\,[0-9]{2})?
    |
        [0-9]*
        (?:[\.\,][0-9]{2})?
    )$
    

    And this variation captures the separators used:

    ^[+-]?[0-9]{1,3}
    (?:
        (?:(?<thousand>\,)[0-9]{3})*
        (?:(?<decimal>\.)[0-9]{2})?
    |
        (?:(?<thousand>\.)[0-9]{3})*
        (?:(?<decimal>\,)[0-9]{2})?
    |
        [0-9]*
        (?:(?<decimal>[\.\,])[0-9]{2})?
    )$
    

    edit 1: “cents” are now optional;
    edit 2: text added;
    edit 3: second solution added;
    edit 4: complete solution added;
    edit 5: headings added;
    edit 6: capturing added;
    edit 7: last answer broke in two versions;

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

Sidebar

Related Questions

I need a RegEx that can handle an integer between 1 - 999 or
Hi I need a Regex that can actually get any letter that is inserted
I need a regex that will get the name of a label. The labels
Hello I need to find regex that would get middle section of this text:
I need to rename approximately 50,000 files and can't find regex examples that work.
I need a regex that also matches Chinese, Greek, Russian, ... letters. What I
I need a regex for four-digit numbers separated by comma (default can also be
I need a regex that matches the following (the brackets indicate I want to
I need a regex that will give me the following results from each example
I need a regex for PropertyName e.g. HelloWorld2HowAreYou would get: Hello HelloWorld2 HelloWorld2How etc.

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.