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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:56:21+00:00 2026-06-12T20:56:21+00:00

Hello I am new to regular expressions and from what I understood from the

  • 0

Hello I am new to regular expressions and from what I understood from the c++ reference website it is possible to get match results.

My question is: how do I retrieve these results? What is the difference between smatch and cmatch? For example, I have a string consisting of date and time and this is the regular expression I wrote:

"(1[0-2]|0?[1-9])([:][0-5][0-9])?(am|pm)"

Now when I do a regex_search with the string and the above expression, I can find whether there is a time in the string or not. But I want to store that time in a structure so I can separate hours and minutes. I am using Visual studio 2010 c++.

  • 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-12T20:56:22+00:00Added an answer on June 12, 2026 at 8:56 pm

    If you use e.g. std::regex_search then it fills in a std::match_result where you can use the operator[] to get the matched strings.

    Edit: Example program:

    #include <iostream>
    #include <string>
    #include <regex>
    
    void test_regex_search(const std::string& input)
    {
        std::regex rgx("((1[0-2])|(0?[1-9])):([0-5][0-9])((am)|(pm))");
        std::smatch match;
    
        if (std::regex_search(input.begin(), input.end(), match, rgx))
        {
            std::cout << "Match\n";
    
            //for (auto m : match)
            //  std::cout << "  submatch " << m << '\n';
    
            std::cout << "match[1] = " << match[1] << '\n';
            std::cout << "match[4] = " << match[4] << '\n';
            std::cout << "match[5] = " << match[5] << '\n';
        }
        else
            std::cout << "No match\n";
    }
    
    int main()
    {
        const std::string time1 = "9:45pm";
        const std::string time2 = "11:53am";
    
        test_regex_search(time1);
        test_regex_search(time2);
    }
    

    Output from the program:

    Match
    match[1] = 9
    match[4] = 45
    match[5] = pm
    Match
    match[1] = 11
    match[4] = 53
    match[5] = am
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have a regular website, and I am adding a new link to
hello I'm new to PHP programming and I migrated from ASP .net to PHP..
Hello I am new to assembly and I'm struggling to get a two-part program
Hello I am new at Haskell and i'm having problems trying to get this
I fairly new to regular expressions and need some help. I need to filter
I'm not new to Python but a complete newbie with regular expressions (on my
I am new to regular expression. I am trying to match a group of
With Regular Expressions I'm trying to remove all the methods/functions from the following code.
I'm new to Regular Expressions... I've been asked a regular expression that accepts Alphanumerics,
I'm pretty new to regular expressions, but I'm sure a regex would give me

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.