Skip to content

Instantly share code, notes, and snippets.

@kazmura11
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazmura11/10982891 to your computer and use it in GitHub Desktop.
Save kazmura11/10982891 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <regex>
int main()
{
std::vector<std::string> test = {
"Windows 8",
"Windows8",
"Microsoft Windows8",
"MicrosoftWindows8",
"Windows8.1",
"MicrosoftWindows8.1",
"Windows 8.1",
"Windows 8.1 Update 1",
"MicrosoftWindows8.1Update1",
"Microsoft Windows 8.1 Update 1",
"microsoft windows 8.1 update 1",
"Microsoft windows 8.2 update 1",
};
std::regex pattern("([Mm]icrosoft)?\\s*([Ww]indows)\\s*(8\\.1)\\s*([Uu]pdate)?.*");
std::smatch sm;
int line = 1;
for (auto it = test.begin(); it != test.end(); ++it)
{
if (std::regex_match(*it, sm, pattern))
{
std::cout << line << "個目の ["
<< sm[0] << "] がマッチしました\n";
}
line++;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment