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

  • Home
  • SEARCH
  • 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 6528211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:30:49+00:00 2026-05-25T09:30:49+00:00

After calling std::regex_search , I’m only able to get the first string result from

  • 0

After calling std::regex_search, I’m only able to get the first string result from the std::smatch for some reason:

Expression.assign("rel=\"nofollow\">(.*?)</a>");
if (std::regex_search(Tables, Match, Expression))
{
    for (std::size_t i = 1; i < Match.size(); ++i)
        std::cout << Match[i].str() << std::endl;
}

So I tried to do it another way – with an iterator:

const std::sregex_token_iterator End;
Expression.assign("rel=\"nofollow\">(.*?)</a>");
for (std::sregex_token_iterator i(Tables.begin(), Tables.end(), Expression); i != End; ++i)
{
    std::cout << *i << std::endl;
}

This does go through every match, but it also gives me the whole matching string instead of just the capture that I was after. Surely must be another way than having to do another std::regex_search on the iterator element in the loop?

Thanks in advance.

  • 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-25T09:30:49+00:00Added an answer on May 25, 2026 at 9:30 am

    regex_token_iterator takes an optional fourth argument specifying which submatch is returned for each iteration. The default value of this argument is 0, which in case of the C++ (and many other) regexes means “the whole match”. If you want to get the first captured submatch, simply pass 1 to the constructor:

    const std::sregex_token_iterator End;
    Expression.assign("rel=\"nofollow\">(.*?)</a>");
    for (std::sregex_token_iterator i(Tables.begin(), Tables.end(), Expression, 1); i != End; ++i)
    {
        std::cout << *i << std::endl; // *i only yields the captured part
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I get the HTTP status code (eg 200 or 500) after calling
After asking organising my Python project and then calling from a parent file in
I have an std::vector of objects and i cycle it calling some methods of
I get a EXC_BAD_ACCESS right after calling this piece of code in my app
I want to do an simple script language in C++ After calling string statement
Summary: I want to to create a templateField resulting from a database after calling
After calling notifydatasetchanged(); I want to scroll to the bottom of list so that
Is it possible somehow to close StreamReader after calling ReadToEnd method in construction like
I would like to know if after calling functions the data I have in
I am having a problem with Vlad on windows. After calling rake vlad:deploy I

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.