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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:22:14+00:00 2026-05-28T01:22:14+00:00

I need to represent version numbers as regular expressions. The broad definition is Consist

  • 0

I need to represent version numbers as regular expressions. The broad definition is

  1. Consist only of numbers
  2. Allow any number of decimal points (but not consecutively)
  3. No limit on maximum number

So 2.3.4.1,2.3,2,9999.9999.9999 are all valid whereas 2..,2.3. is not.

I wrote the following simple regex

'(\d+\.{0,1})+'

Using it in python with re module and searching in ‘2.6.31’ gives

>>> y = re.match(r'(\d+\.{0,1})+$','2.6.31')
>>> y.group(0)
'2.6.31'
>>> y.group(1)
'31'

But if I name the group, then the named group only has 31.

Is my regex representation correct or can it be tuned/improved? It does not currently handle the 2.3. case.

  • 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-28T01:22:15+00:00Added an answer on May 28, 2026 at 1:22 am

    The notation {0,1} can be shortened to just ?:

    r'(\d+\.?)+$'
    

    However, the above will allow a trailing .. Perhaps try:

    r'\d+(\.\d+)*$'
    

    Once you have validated the format matches what you expect, the easiest way to get the numbers out is with re.findall():

    >>> ver = "1.2.3.4"
    >>> re.findall(r'\d+', ver)
    ['1', '2', '3', '4']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We need to represent huge numbers in our application. We're doing this using integer
I need to represent an IEEE 754-1985 double (64-bit) floating point number in a
I need to store numbers that represent currency amounts in 2dp to be output
I have a number that represents a software version (ex: 1.2.0.14) and I need
I need to represent inheritance like Person/Student. How do you do that in LInqToSql?
I need to represent calculator key presses by the text for the keys to
I need to represent immutable vectors in Python (vectors as in linear algebra, not
I need a way to represent a 2-D array (a dense matrix) of doubles
I need to build a class that will represent a row in some table
I need a way for a single variable to represent two kinds of objects

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.