Skip to content

Instantly share code, notes, and snippets.

@zaltoprofen
Last active August 29, 2015 14:02
Show Gist options
  • Save zaltoprofen/104f70ad38b988e8cc74 to your computer and use it in GitHub Desktop.
Save zaltoprofen/104f70ad38b988e8cc74 to your computer and use it in GitHub Desktop.
#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