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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:03:57+00:00 2026-05-27T09:03:57+00:00

I am trying to parse some text using boost. i have looked at the

  • 0

I am trying to parse some text using boost. i have looked at the example on the official site but it doesn’t seem to be working. I have written my own example; it doesn’t enter the while loop at all.

#include <boost/regex.hpp>
using namespace std;

int main(void)
{
    string s;
    string::const_iterator st, en;
    s = "int_node:0 int_node:1 link_latency:1 bw_multiplier:16 link_weight:1\n"
       "int_node:0 int_node:2 link_latency:1 bw_multiplier:16 link_weight:1\n"
       "int_node:0 int_node:3 link_latency:1 bw_multiplier:16 link_weight:1\n"
       "int_node:0 int_node:4 link_latency:1 bw_multiplier:16 link_weight:1\n"
       "int_node:0 int_node:5 link_latency:1 bw_multiplier:16 link_weight:1\n"
       "int_node:0 int_node:6 link_latency:1 bw_multiplier:16 link_weight:1\n"
       "int_node:0 int_node:7 link_latency:1 bw_multiplier:16 link_weight:1";

    st = s.begin();
    en = s.end();
    boost::regex expression("int_node:([0-9]+) int_node:([0-9]+)"
                            " link_latency:([0-9]+) bw_multiplier:([0-9]+)"
                            " link_weight:([0-9]+) long_range:([0-9]+)"
                        " no_of_vcs:([0-9]+)");

    boost::match_results<std::string::const_iterator> what;


    boost::match_flag_type flags = boost::match_default;

    while(boost::regex_search(st, en, what, expression, flags))
    {
      st = what[0].second;
          flags |= boost::match_prev_avail;
          flags |= boost::match_not_bob;

      cout << what[1] << " " << what[2] << " " << what[3] << "\n";
    }

    return 0;
}

I am trying to parse a file that looks like this:

int_node:0 int_node:1 link_latency:1 bw_multiplier:16 link_weight:1
int_node:0 int_node:2 link_latency:1 bw_multiplier:16 link_weight:1
int_node:0 int_node:3 link_latency:1 bw_multiplier:16 link_weight:1
int_node:0 int_node:4 link_latency:1 bw_multiplier:16 link_weight:1

and retrieve the integer values for each field.

  • 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-27T09:03:57+00:00Added an answer on May 27, 2026 at 9:03 am

    Your regular expression has 7 elements but each line you’re searching only has 5.

    You could try one of two options. Either reduce the number of elements to only 5

        boost::regex expression("int_node:([0-9]+) int_node:([0-9]+) link_latency:([0-9]+) bw_multiplier:([0-9]+) link_weight:([0-9]+)");
    

    or, if there will be some lines that might have the last two elements (and you want to reference them), use a positive look-ahead assertion like this:

        boost::regex expression("int_node:([0-9]+) int_node:([0-9]+) link_latency:([0-9]+) bw_multiplier:([0-9]+) link_weight:([0-9]+)(?= long_range:([0-9]+) no_of_vcs:([0-9]+))?");
    

    If you’re not familiar with regex, the (?:REGEX)? will say that the last two elements are optional, and the ?: at the beginning means this particular grouping doesn’t count. If there is a value in the 6th column (long_range), then what[6] will contain the long_range value, otherwise it will be blank.

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

Sidebar

Related Questions

I'm trying to parse some text using PyParser. The problem is that I have
I have a string: [\n['-','some text what\rcontains\nnewlines'],\n\n trying to parse: Regex.Split(@[\n['-','some text what contains
I'm trying to parse an mrss feed using jquery but am having some difficulty
I am using Boost::Spirit to parse some text into structs. This requires using BOOST_FUSION_ADAPT_STRUCT
I'm trying to parse a XML using Apache Commons JXPath. But for some reason,
I am trying to parse some text and diagram it, like you would a
Trying to parse an HTML document and extract some elements (any links to text
Trying to parse some XML but apparently this is too much for a lazy
I'm trying to parse some JSON using the JSon.Net library. The documentation seems a
I am trying to parse some XML i have retrieved via e4x in an

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.