// Copyright (C) 2018 The C++ Regex Testing Project -- or whatever
//
// build & run:
//   make regex && ./regex
//
// or:
//   g++ regex.cpp -o regex
//   ./regex [<test input>] [<test regex>]
//
// expected output:
//   match: "      26     2373 RETURN     all  --  wlan0  rmnet0  0.0.0.0/0"
//   match: "26"
//   match: "2373"
//   match: "wlan0"
//   match: "rmnet0"
//   match: "0.0.0.0/0"
//
#include <regex>
#include <iostream>

using std::cout;
using std::regex;
using std::string;

int main(int argc, char* argv[]) {
	static const char TEST_RE[] =
		R"(\s*(\d+)\s+(\d+)\s+RETURN\s+all\s+--\s+(\w+)\s+(\w+)\s+([\w.:/]+))";
	static const char TEST_INPUT[] =
		"   26    2373 RETURN   all  --  wlan0  rmnet0  0.0.0.0/0     0.0.0.0/0";

	const string in = (argc > 1) ? argv[1] : TEST_INPUT;
	const regex re((argc > 2) ? argv[2] : TEST_RE);

	std::smatch matches;
	if (!std::regex_search(in, matches, re)) {
		cout << "no match\n";
		exit(1);
	}
	for (const auto& m : matches) {
		cout << "match: \"" << m.str() << "\"\n";
	}
}
