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

The Archive Base Latest Questions

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

Can anybody help to create a regex to handle this sutuation. There is a

  • 0

Can anybody help to create a regex to handle this sutuation.
There is a display format string for numerics values, which can be in following format
positive_value_format;negative_value_format.
Positive and negative formats can be for example ‘#,##0.00;(#,##0.0000)’ or ‘#,##0;(#,##0.0)’ or ‘#,##0’ – it means that one positive value should be shown with 2 digits after the dot, another – with no digits.

so I need to create regex to handle this 3 cases, what is the number of decimal places for positive and\or negative values.

‘#,##0.00;(#,##0.0000)’ -> 2, 4
‘#,##0;(#,##0.0)’ -> 0, 1
‘#,##0’ -> 0

I’ve found following questions, but they are not answered or use parsing strings instead of RegExp – What would be a good way of determining number of decimal places from a format string?, identify the number of decimal places based on the format string

  • 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-16T01:31:51+00:00Added an answer on June 16, 2026 at 1:31 am

    This works with all 3 provided strings

            string pat = "#,##([0-9]([0-9.]*?|$))($|;[(]#,##[0-9]([0-9.]*?)[)])";
            Match m = Regex.Match(input, pat);
    
            int lengthA = m.Result("$2").Replace(".", "").Length;
            if (!String.IsNullOrWhiteSpace(m.Result("$4")))
            {
                int lengthB = m.Result("$4").Replace(".", "").Length;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody help me understand why are there two loops here? <?php // create
Hi can anybody help me on this issue, like i was trying to create
Can anybody help me to create function that will accept for parameter xml string
can anybody help me understand how Honda achieved this effect: http://testdays.hondamoto.ch/ I mean the
Can anybody help me with this simple code?? #include <iostream> using namespace std; void
Can anybody help me? I'm trying to create a ListView in Android, and I'm
I got the exception to create. Can anybody help me? How to write nested
Can anybody help me with this? Here's the problem... When I have to code
Can anybody help me out, while my solution does not seem to work: $this->db->where('stock
Can anybody help me to fix this code, I really need it, but have

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.