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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:55:58+00:00 2026-05-20T00:55:58+00:00

I have a string that’s of the following scheme: VersionNumber.VersionString-VersionNumber.VersionString Such that the following

  • 0

I have a string that’s of the following scheme:

VersionNumber.VersionString-VersionNumber.VersionString

Such that the following example strings can be converted into arrays of information:

1. 1.x-2.x             => (1, 'x', '2', 'x')
2. 1.2-3.4             => (1, 2, 3, 4)
3. 1.2-3.4-beta5       => (1, 2, 3, '4-beta5')
4. 1.2-beta3-3.4       => (1, '2-beta3', 3, 4)
5. 1.2-beta3-4.5-beta6 => (1, '2-beta3', 4, '5-beta6')

The logic for the parse is:

  1. First element is everything before the first period.
  2. Second element is everything up to a hyphen immediately before a number.
  3. Third element always starts with a number and is everything up to the next period.
  4. Fourth element is everything after the period.

Notes:

  • Second element is an arbitrary string, but will never have a hyphen that immediately precedes a number (e.g. 2-3 is not valid, but 2-beta4 is).
  • Third element always starts with a number, and begins right after a hyphen.

I’ve been able to parse the first three cases using the following expression:

(.+?).(.+?)-(.+?).(.*)

But I’m not sure how to modify it to handle cases 4 and 5 (when the second element contains a hyphen). The two approaches I thought of were:

  1. Modify the second group to match everything before a hyphen immediately preceding a digit.
  2. Modify the second group to match everything until it hits a second hyphen only if the first hyphen immediately precedes a non-digit character.

Presumably the first approach is the correct/simplest way to do it, but I’m struggling with coming up with the correct regexp to express 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. Editorial Team
    Editorial Team
    2026-05-20T00:55:59+00:00Added an answer on May 20, 2026 at 12:55 am

    Can VersionString ever contain a dot? If not, this should work:

    (\d+)\.([^.]+)-(\d+)\.(\S+)
    

    The [^.]+ initially matches everything up to the next dot, but then backtracks a little bit. If VersionString can contain a dot, you can use this:

    (\d+)\.(\S+?)-(\d+)\.(\S+)
    

    Matching digits explicitly in the VersionNumber part serves to enforce your “digit preceded by a hyphen” rule.

    (Actually, (.+?) works just as well; I used (\S+?) because I was testing the regex plucking the version strings out of the full text of your message.)

    EDIT: Per the comments below, here’s the final version:

    (\d+[^.]*)\.(\S+?)-(\d+[^.]*)\.(\S+)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that is uncertain,I have the following strings: ST,NT,+ 16KG ~YT,NT,+
I have a string that contains the following 7 bits: 1101000. How can I
I have a string that says 15:00:00 how can I limit the length of
I have a string that looks like string url = "www.example.com/aaa/bbb.jpg"; "www.example.com/" is 18
I have String s that are put into an ArrayList randomly. private ArrayList<String> teamsName
I have a string that is one of the following forms ABC // all
I have string that is in format January 1, 2008 how can I parseExact
I have a string that holds a value in the format of ddMMyyhhmmss. Example
I have a string that when I var_dump returns the following string(20) {\key1\:\key1_value,\key2\:\key2_value\} How
I have a string that is 141 characters in length. Using the following code

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.