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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:56:40+00:00 2026-06-07T17:56:40+00:00

I’m pretty new with regexp and I can’t get my function doing what I

  • 0

I’m pretty new with regexp and I can’t get my function doing what I would like.
I have a long string, and I want to extract from it, 3 variables.

My string looks :

 Infoname/info :   
 Input_Device_Name GTape  Buffer_Size 16384 Acquisition_Event_Rate 163691.000000  
 Acquisition_Buffer_Rate 14873.333008 Acquisition_Succes_Rate 100.000000

And my goal is to store 163691.000000, 14873.333008 and 100.000000 in three differents variables.

What is the fastest and nicest way to do it please ?

Thank you,
eo

  • 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-07T17:56:42+00:00Added an answer on June 7, 2026 at 5:56 pm

    You could use the following regex to look for it:

    "Input_Device_Name\s+GTape\s+Buffer_Size\s+[0-9.]+\s+Acquisition_Event_Rate\s+([0-9.]+)\s+Acquisition_Buffer_Rate\s+([0-9.]+)\s+Acquisition_Succes_Rate\s+([0-9.]+)"
    

    This should catch the three values assuming that your text stays the same and that your numbers always take this form (i.e. are positive and not in exponential form.) Note that only the last three numbers are captured by putting brackets round them.

    If you use boost regex, you could do something like this:

    #include <boost/regex.hpp>
    

    …

    boost::smatch what;
    static const boost::regex pp("Input_Device_Name\\s+GTape\s+Buffer_Size\\s+[0-9.]+\\s+Acquisition_Event_Rate\\s+([0-9.]+)\\s+Acquisition_Buffer_Rate\\s+([0-9.]+)\\s+Acquisition_Succes_Rate\\s+([0-9.]+)");
    if ( boost::regex_match(inputTextString, what, pp) )
    {
        if ( what.size() == 4 )
        {
             double d1 = strtod(static_cast<const string&>( what[1] ).c_str(), NULL, 0);
             double d2 = strtod(static_cast<const string&>( what[2] ).c_str(), NULL, 0);
             double d3 = strtod(static_cast<const string&>( what[3] ).c_str(), NULL, 0);
    
             // These are your doubles, do some stuff with them.
        }
    }
    

    Where inputTextString contains the line of text you want to parse, so if this is coming from a file say, you would want to place this code in a loop. The what variable is a vector of all the matching text though what[0] contains the whole line and so can be ignored unless you need it. Last but not least, remember to double escape the ‘space’ character class otherwise it will already be processed (or generate an error or warning) by the compiler prior to being presented to the regex processor. Also, please note that I’ve not had time to compile this, though it is based on working code

    Watch out for trailing, leading space on your input file and use ^ and $ to mark the beginning or end of the line respectively if it helps.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
Does anyone know how can I replace this 2 symbol below from the string

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.