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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:50:05+00:00 2026-05-15T10:50:05+00:00

I want to capture named substring with the pcre++ library. I know the pcre

  • 0

I want to capture named substring with the pcre++ library.

I know the pcre library has the functionality for this, but pcre++ has not implemented this.

This is was I have now (just a simple example):

pcrepp::Pcre regex("test (?P<groupName>bla)");

if (regex.search("test bla"))
{
    // Get matched group by name
    int pos = pcre_get_stringnumber(
        regex.get_pcre(),
        "groupName"
    );
    if (pos == PCRE_ERROR_NOSUBSTRING) return;

    // Get match
    std::string temp = regex[pos - 1];

    std::cout << "temp: " << temp << "\n";
}

If I debug, pos return 1, and that is right, (?Pbla) is the 1th submatch (0 is the whole match). It should be ok. But… regex.matches() return 0. Why is that :S ?

Btw. I do regex[pos – 1] because pcre++ reindexes the result with 0 pointing to the first submatch, so 1. So 1 becomes 0, 2 becomes 1, 3 becomes 2, etc.

Does anybody know how to fix this?

  • 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-15T10:50:06+00:00Added an answer on May 15, 2026 at 10:50 am

    My mistake unfortunately, I tested the regex in my real program and there the regex was different. I used something like this:

    (?:/(?P<controller>[^/]+)(?:/(?P<action>[^/]+))?)?
    

    So the group name to number conversion goes well, but when i try to access the group i get index of range because of the (?: … )? groups. I just added a check if the group index i in the correct range, it is i could use the group.

    Sorry for asking it here too early.

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

Sidebar

Related Questions

i want to capture all tags named 'STRONG' i can use <STRONG.*?</STRONG> this is
I have a Camtasia project named aaa.camrec and want to capture an image in
I want to capture the browser window/tab close event. I have tried the following
I want to capture part of a string and I know it involves some
Suppose I have files named like GATES, Bill.jpg and I want to rename them
How do I use named captures when performing Regex.Replace? I have gotten this far
I have a dynamically generated list of students. I want the users to capture
I have an existing form which is tied to a model named 'Order', but
I have a number of 0-12345-67890 and I want to capture 0123456789 in a
I have this string circle,4.5 square,3.1 circle,2.0 triangle,4.7,4.9 square,4.1 circle,4.3 Lets say I want

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.