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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:55:45+00:00 2026-05-19T04:55:45+00:00

Say if I have an initial string that could contain either an integer or

  • 0

Say if I have an initial string that could contain either an integer or a double, followed by a timescale. Eg, it could be 5.5hours or 30 mins, etc. The data I will be receiving in this format is notoriously none uniformed so, for example, I could receive data such as 5.5 hours. With the added full stop.

I wanted a way to extract an integer or double from such strings, however I am struggling with the possible inclusion of additional full stops/periods. I can easily isolate the numbers and fullstops by replacing the letters with emptyspace.

Can anybody please advise.

Thanks.

  • 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-19T04:55:46+00:00Added an answer on May 19, 2026 at 4:55 am
    \d+(?:\.\d+)?
    

    should match your criteria:

    \d+  # Match one or more digits
    (?:  # Try to match the following group:
     \.  # a dot
     \d+ # one or more digits
    )?   # End of optional group 
    

    So, to iterate over all matches in your string:

    Regex regexObj = new Regex(@"\d+(?:\.\d+)?");
    Match matchResults = regexObj.Match(subjectString);
    while (matchResults.Success) {
        // matched number: matchResults.Value
        matchResults = matchResults.NextMatch();
    }
    

    This regex will not match numbers in exponential notation like 1.05E-6, obviously.

    If you also want to catch the following timescale, then you can use

    (\d+(?:\.\d+)?)\s*(\w+)
    

    Now, after a match, matchResults.Groups[1] will contain the number. matchResults.Groups[2] will contain the word following the number which you can then check against your list of allowed words. This word is mandatory, i. e. if it’s missing, the entire regex will fail – if you don’t want that, add a ? at the end.

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

Sidebar

Related Questions

Say I have a list of 10,000 lines of string that needs to be
Say I have two strings, String s1 = AbBaCca; String s2 = bac; I
Let's say I have a class that exposes one property. Is it considered to
Say I have the following XML <?xml version=1.0 encoding=utf-8?> <Person> <FirstName>Bjorn</FirstName> <LastName>Ellis-Gowland</LastName> </Person> That
Say I have a complex stylesheet with lots of interacting styles etc. For a
Say I have a class with synchronized methods. It's actually a class that uses
Say I have an object in 2D space that can rotate and then should
Say I have a string text, a caret position caret and then want to
Let's say have something like: SELECT energy_produced, energy_consumed, timestamp1 AS timestamp FROM ( SELECT
Say we have the following method: private MyObject foo = new MyObject(); // and

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.