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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:51:09+00:00 2026-05-10T23:51:09+00:00

I am trying to learn more about regular expressions I have one below that

  • 0

I am trying to learn more about regular expressions I have one below that I believe finds cases where there is a missing close paren on a number up to 999 billion. The one below it I thought should do the same but I do not get similar results

   missingParenReg=re.compile(r'^\([$]*[0-9]{1,3}[,]?[0-9]{0,3}[,]?[0-9]{0,3}[,]?[0-9]{0,3}[.]*[0-9]*[^)]$')    missingParenReg2=re.compile(r'^\([$]?([0-9]{1,3}[,]?)+[.]*[0-9]*[^)]$') 

I think the second one says: There must be an open paren to start
There may or may not be as many as one dollar sign
The next group must exist at least once but can exist an unlimited number of times
The group should have at least one digit but may have as many as three
The group may have as few as 0 and as many as 1 commas
Following this group there may or may not be a decimal point
If there is a decimal point it will be followed by as many as 0 but as many as uncounted occurences of digits
At the end there should not be a closing paren.

I am trying to understand this magic stuff so I would appreciate a correction to my regex (if it can be corrected) in addition to a more elegant solution if you have it.

  • 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. 2026-05-10T23:51:10+00:00Added an answer on May 10, 2026 at 11:51 pm

    The trickier part about regular expressions isn’t making them accept valid input, it’s making them reject invalid input. For example, the second expression accepts input that is clearly wrong, including:

    • (1,2,3,4 — one digit between each comma
    • (12,34,56 — two digits between each comma
    • (1234......5 — unlimited number of decimal points
    • (1234,.5 — comma before decimal point
    • (123,456789,012 — if there are some commas, they should be between each triple
    • (01234 — leading zero is not conventional
    • (123.4X — last char is not a closing paren

    Here’s an alternative regular expression that should reject the examples above:

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

    • Optional leading plus/minus.
    • Optional dollar sign.
    • Three choices separated by |:
      • Single zero digit (for numbers like 0.5 or simply 0).
      • Any number of digits with no commas. The first digit must not be zero.
      • Comma-separated digits. The first digit must not be zero. Up to three digits before the first comma. Each comma must be followed by exactly three digits.
    • Optional single decimal point, which must be followed by one or more digits.

    Regarding the parens, if all you care about is whether the parens are balanced, then you can disregard parsing out the numeric format precisely; just trust that any combination of digits, decimal points, and commas between the parens are valid. Then use the (?!...) construct that evaluates as a match if the input doesn’t match the regular expression inside.

    (?!\([$\d.,]+\))

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

Sidebar

Related Questions

I have been trying to learn more about lambda expressions lately, and thought of
In my quest in trying to learn more about OOP in PHP. I have
I'm new to regular expressions, but I'm trying to learn about it. I want
I'm trying to learn more about how systems really work underneath all the pretty
I am trying to learn more about the mechanics of executable files, but I
I've been lately trying to learn more and generally test Java's serialization for both
I'm trying to learn a little more on vectormath through writing a simple ray
In trying to learn how to create objects in ActionScript, I have had no
Possible Duplicate: Copy a linked list Hello stackoverflow! I am trying to learn more
I was wondering where I could learn more about decentralized sharing and P2P networks.

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.