Last active
August 29, 2015 14:02
-
-
Save zaltoprofen/104f70ad38b988e8cc74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <regex> | |
#include <string> | |
int main(int argc, char const* argv[]) | |
{ | |
using namespace std; | |
regex r("hoge:(abc)"); | |
smatch res; | |
string input = "hoge:abc"; | |
string expected = "abc"; | |
if(regex_match(input, res, r)){ | |
cout << "expected: \"" << expected << "\"\n" | |
<< "actual: \"" << res[1].str() << "\"" << endl; | |
} else { | |
cout << "Unmatched" << endl; | |
} | |
return 0; | |
} | |
// $ g++ --version | |
// g++ (GCC) 4.8.3 | |
// Copyright (C) 2013 Free Software Foundation, Inc. | |
// This is free software; see the source for copying conditions. There is NO | |
// warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
// $ | |
// $ g++ -std=c++11 regex_match_sample.cc;./a.out | |
// expected: "abc" | |
// actual: ":abc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment