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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:15:07+00:00 2026-05-13T06:15:07+00:00

The answer to this may be a simple no, but here goes… I’m currently

  • 0

The answer to this may be a simple no, but here goes…

I’m currently using the boost function regex_match to evaluate a string against a regex value.

Instead of just returning T/F, is there a way to find out which element of multiple joined statements evaluated to true?

For example:

^a$|^z$|^p$

a --> 0
z --> 1
f --> -1
  • 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-13T06:15:07+00:00Added an answer on May 13, 2026 at 6:15 am

    Enclose them in capturing parentheses, then test which sub-expression matched.

    (^a$)|(^z$)|(^p$)
    
    
    match_results m;
    regex_match(..., m);
    

    a -> m[1].matched

    z -> m[2].matched

    p -> m[3].matched

    Update:

    You might be able to improve on it by making a single capture group and testing the result, e.g.:

    ^([azp])$
    ...
    if ('a' == m[0][0]) ...
    

    Either method is almost certainly faster than calling regex_match three times, though to be sure you just have to test it. Unless you’re doing this really often, the difference is not worth worrying about.

    Obviously, make sure that you’re only setting up the regex once, not each time you need it.

    If need it to be really, really fast you probably shouldn’t be using a regex.

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

Sidebar

Related Questions

This may be a simple answer, but I'm trying to add a dom-created element
This may be a very simple problem, but I couldn't find an answer googleing
This may have a simple answer (and I hope it does) but looking online
This question may be beyond the scope of a simple answer here at stack
I'm new to jQuery so this may be a real simple answer. I have
This question may have been asked before, but I had trouble finding an answer,
I know this is a total newbie question, but the answer may not be
Being that my C++ isn't that great, this may be a really simple/obvious answer,
There is probably a very simple answer to this, but I want to be
This may be a fairly simple question, but I can't seem to find the

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.