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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:06:35+00:00 2026-05-31T22:06:35+00:00

I am trying to find all floating number (could be in exponential forms with

  • 0

I am trying to find all floating number (could be in exponential forms with -/+ prefix or not). For example, the following is the valid format: -1.2 +1.2 .2 -3 3E4 -3e5 e-5

The source of text contains several numbers separated with space or comma. I need to use regular expression to tell

  1. tell if there is any invalid number (e.g. 1.2 3.2 s3) s3 is not a valid one
  2. list every single valid number

I have no idea how to get (1) done but for (2), I am using boost::regex and the following code

wstring strre("[-+]?\\b[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?\\b");
wstring src("1.2 -3.4 3.2 3 2 1e-3 3e3");
boost::wregex regexp(strre);
boost::match_results<std::wstring::const_iterator> what; 
regex_search(src, what, regexp, boost::match_continuous);
wcout << "RE: " << strre << endl << endl;
wcout << "SOURCE: [" << src << "]" << endl;

for (int i=0; i<what.size(); i++)
  wcout << "OUTPUT: [" << wstring(what[i].first, what[i].second) << "]"<< endl;

But this code only show me the first number (1.2). I also try boost::match_all, boost::match_default, the same result.

ADDITIONAL INFO:
Hi all, let’s not worry about double backslash issue, it is correctly expressed in my code (because in my testing code, I read the string from a text not by explicit string). Anyway, I modify the code as follow

wstring strre("[-+]?\\b[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?\\b");
boost::wregex regexp(strre);
boost::match_results<std::wstring::const_iterator> what; 
wcout << "RE: " << strre << endl << endl;
while (src.length()>0)
{
  wcout << "SOURCE: [" << src << "]" << endl;
  regex_search(src, what, regexp, boost::match_default);
  wcout << "OUTPUT: [" << wstring(what[0].first, what[0].second) << endl;
  src = wstring(what[0].second, src.end());
}

Now, it is correctly show everything single numbers but I have to run regex_search several time due to it only give one number at a time. Well, I just don’t understand why regex_search won’t give me all results instead. Is that any way to run the search once and get all the results back?

  • 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-31T22:06:36+00:00Added an answer on May 31, 2026 at 10:06 pm

    You normally have to double-escape backslash things in a C++ string. So your "\." turns into just .. You would need it to be "\\.", etc. Similarly, your "\b" becomes not a word-boundary but rather a literal backspace! Fix the same way: "\\b".

    Also, where’s the doc for that strre class? Are you sure it understands the language you are using?

    Apparently the new C++ standard has raw string literals. These work like `backticked` strings in Go, or like ‘single-quoted’ strings or /patterns/ in Perl. See this answer for details.

    EDIT

    Here’s a somewhat fancier pattern for detecting floating-point literals, but which uses no backslashes:

     [+-]?(?=[.]?[0-9])[0-9]*(?:[.][0-9]*)?(?:[Ee][+-]?[0-9]+)?
    

    Note that it does require lookaheads, which EREs don’t support. You should probably use the PCRE library, which does. Broken down, that’s

    [+-]?                   # optional leading sign
    (?=[.]?[0-9])           # lookahead for a digit, maybe with an intervening dot
    [0-9]*                  # maybe some digits
    (?:[.][0-9]*)?          # maybe a (dot plus maybe some digits)
    (?:[Ee][+-]?[0-9]+)?    # maybe an exponent, which may have a sign and must have digits
    

    Pattern courtesy of Perl’s Regexp::Common library.

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

Sidebar

Related Questions

I am trying to find all two number digits only in the following list
I am trying to find all possible ways I could improve my website performance.
I'm trying to find all files that are not up to date compared to
I'm trying to find all records where two conditions are true. For example: ruby-1.8.7-p302
I have the following sql statement - it's trying to find all the zipcodes
I'm trying to find all of the quoted text on a single line. Example:
I'm trying to find all topics in a one particular category, but I'm not
I'm trying to find all strings of the format {{rdex|001|001|Bulbasaur|2|Grass|Poison}} in a large text
I am trying to find all the digits following a certain String pattern using
I'm trying to find all data items that have long/lats that are contained by

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.