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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:04:10+00:00 2026-06-10T04:04:10+00:00

Can any body give me some regular expression patterns which will extract the version

  • 0

Can any body give me some regular expression patterns which will extract the version numbers(1.5) from some sample strings like

    "jdk1.5","jdk-v1.5","jdk-V1.5","jdk V1.5","jdkv1.5","jdk version1.5","1.5.6","v1.5","V1.5","version 1.5","Version 1.5","14.5.4","1.5.4","14.5.4""jdj14.5"

I want to store the regex patterns in a string array and will check these patterns with the above strings. If there is a match with any of the stored patterns, then the output should be the version number 1.5. I want to extract the version numbers (1.5) only from the above strings.

valid string formats :
“jdk1.5″,”jdk-v1.5″,”jdk-V1.5″,”jdk V1.3″,”jdkv1.4″,”jdk version1.5″,”1.5.6″,”v1.5″,”V1.5″,”version 1.5″,”Version 1.5″,”14.5.4″,”1.5.4″,”14.5.4″”jdj14.5″,”14.52.3.42”

Invalid String formats : “jdk1..2″,”jdk.1.2.”,”.1.2.”

  • 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-10T04:04:11+00:00Added an answer on June 10, 2026 at 4:04 am

    Requirements

    If you can formulize what you want as:

    1. Anything in format 1.5 or 1.5.6 or 1.5.6.7 or 1.5.6.7.8 etc. is valid version number by default (numbers can be one or more digits like 12.60.70).
    2. A version number 1.5 can be followed by a dot (.) only if it is in the format 1.5.6.
    3. A version number 1.5 never preceded by a dot (.) like .1.5.

    Solution

    Then, I can suggest you this regex:

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

    See it in action, includes all positive samples and excludes all negative samples you provided.

    How to use

    First capture group will be your version number. Sample code:

    Pattern pattern    = Pattern.compile("(?!\\.)(\\d+(\\.\\d+)+)(?![\\d\\.])");
    Matcher matcher    = pattern.matcher(inputStr);
    boolean matchFound = matcher.find();
    
    if (matchFound)
    {
        String version = matcher.group(1);
        System.out.println("Version number: " + version);
    }
    else
    {
        System.out.println("No match for the input!");
    }
    

    Note: This will work only with Java 7+, because look-aheads doesn’t supported by older versions.

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

Sidebar

Related Questions

Can any body please, give me some ideas here. I have a huge table
can any body give me some tips to learn cherrypy? I have learn python,
Any one can give the information about which tools are free for Defect Tracking/Logging
I am developing a site some thing related to mothers . Any body can
Can anybody give any working example of how to read/write Unicode text files using
Can any body help me out how to clear the items in the list
can any body help me the create a menu(Home, My Quote, Send a Quote)
Can any body tell me how can I store Java Date to Mysql datetime...?
Can any body explain me what is a Context and how can i use
Can any body tell me that how many maximum subgraphs of a graph can

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.