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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:27:57+00:00 2026-05-24T10:27:57+00:00

I am learning regular expressions and I am trying to create one that will

  • 0

I am learning regular expressions and I am trying to create one that will validation either a whole number or a decimal.

I have created this regular expression:

^(\d+)|([\d+][\.{1}][\d+])$

It almost works, but it says a number like:

12. 
12..
12..67

are matches.

I thought

([\d+][\.{1}][\d+])

meant it had to have one or more numbers, followed by a dot (and only one), followed by one or more numbers.

Can someone explain what I am doing wrong?

As a learning process I’m interested in what I am doing wrong rather than what is another way of doing it. I tried following the syntax examples but I have missed something.

  • 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-24T10:27:57+00:00Added an answer on May 24, 2026 at 10:27 am

    You are wrong

    ([\d+][\.{1}][\d+])
    

    with the square brackets are you creating character classes. that means

    [\d+] does mean match a digit or a + once.

    [\.{1}] does mean match a . or a { or a 1 or a }

    To get the behaviour you expect remove the square brackets

    (\d+\.{1}\d+)
    

    This will match at least one digit, a . followed by one or more digits

    The other problem here is the ^ belongs only to the first part of your expression and the $ belong only to the last part of your alternation. So you should put brackets around the complete alternation

    ^((\d+)|(\d+\.{1}\d+))$
    

    If you don’t need the match in a capturing group you can remove the brackets around the single alternatives

    ^(\d+|\d+\.{1}\d+)$
    

    As last point as Jens noted

    {1} is redundant \.{1} is the same than \.

    Then we are at

    ^(\d+|\d+\.\d+)$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning about regular expressions and have one question; the answer will help me
I'm trying my hand in learning Regular Expressions in Oracle ( rather, my first
I am learning regular expressions and I am trying find this string day1otlk_XXXX.gif where
I've set myself a somewhat ambitious first task in learning regular expressions (and one
Does anyone have some good resources on learning more advanced regular expressions I keep
I am learning regex ( http://www.regular-expressions.info/ ), and trying to figure out how to
I'm learning about regular expressions for a script I will be writing down the
I need help again with some regular expressions I'm trying to do (still under
I've been learning regular expressions for the last few days and I've been stumbled
I know 8086 Assembly and learning MIPS Assembly. Also, I'm learning Regular Expressions, then

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.