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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:28:33+00:00 2026-05-13T15:28:33+00:00

There are multiple posts on here that capture value , but I’m just looking

  • 0

There are multiple posts on here that capture value, but I’m just looking to check to see if the value is something. More vaguely put; I’m looking to understand the difference between checking a value, and “capturing” a value. In the current case the value would be the following acceptable money formats:

Here is a post that explains some about a money regex but I don’t understand it a bit.

.50
50
50.00
50.0
$5000.00
$.50

I don’t want commas (people should know that’s ridiculous).

The thing I’m having trouble with are:

  1. Allowing for a $ at the starting of the value (but still optional)
  2. Allowing for only 1 decimal point (but not allowing it at the end)
  3. Understanding how it’s working inside
  4. Also understanding out to get a normalized version (only digits and a the optional decimal point) out of it that strips the dollar sign.

My current regex (which obviously doesn’t work right) is:

# I'm checking the Boolean of the following:
re.compile(r'^[\$][\d\.]$').search(value)

(Note: I’m working in Python)

  • 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-13T15:28:33+00:00Added an answer on May 13, 2026 at 3:28 pm

    Assuming you want to allow $5. but not 5., the following will accept your language:

    money = re.compile('|'.join([
      r'^\$?(\d*\.\d{1,2})$',  # e.g., $.50, .50, $1.50, $.5, .5
      r'^\$?(\d+)$',           # e.g., $500, $5, 500, 5
      r'^\$(\d+\.?)$',         # e.g., $5.
    ]))
    

    Important pieces to understand:

    • ^ and $ match only at the beginning and end of the input string, respectively.
    • \. matches a literal dot
    • \$ matches a literal dollar sign
      • \$? matches a dollar sign or nothing (i.e., an optional dollar sign)
    • \d matches any single digit (0-9)
      • \d* matches runs of zero or more digits
      • \d+ matches runs of one or more digits
      • \d{1,2} matches any single digit or a run of two digits

    The parenthesized subpatterns are capture groups: all text in the input matched by the subexpression in a capture group will be available in matchobj.group(index). The dollar sign won’t be captured because it’s outside the parentheses.

    Because Python doesn’t support multiple capture groups with the same name (!!!) we must search through matchobj.groups() for the one that isn’t None. This also means you have to be careful when modifying the pattern to use (?:...) for every group except the amount.

    Tweaking Mark’s nice test harness, we get

    for test, expected in tests:
        result = money.match(test) 
        is_match = result is not None
        if is_match == expected:
          status = 'OK'
          if result:
            amt = [x for x in result.groups() if x is not None].pop()
            status += ' (%s)' % amt
        else:
          status = 'Fail'
        print test + '\t' + status
    

    Output:

    .50     OK (.50)
    50      OK (50)
    50.00   OK (50.00)
    50.0    OK (50.0)
    $5000   OK (5000)
    $.50    OK (.50)
    $5.     OK (5.)
    5.      OK
    $5.000  OK
    5000$   OK
    $5.00$  OK
    $-5.00  OK
    $5,00   OK
            OK
    $       OK
    .       OK
    .5      OK (.5)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 381k
  • Answers 382k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For grins, try nuking your PreferenceCategory. It's not doing you… May 14, 2026 at 10:20 pm
  • Editorial Team
    Editorial Team added an answer Oh, silly me. I fixed it. I forgot to put… May 14, 2026 at 10:20 pm
  • Editorial Team
    Editorial Team added an answer I'd suggest that you rethink your design. Maybe there is… May 14, 2026 at 10:20 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.