#include <regex>
#include <string>
#include <iostream>

int main()
{
	std::string line = "abcde";
    {
    	const std::string RX_ION_TYPE("ab?|ab?(?:cd|dc)");
    
    	const auto regexType = std::regex::ECMAScript;
    
    	std::regex rx_ionType;
    
    	rx_ionType.assign(
    		"(" + RX_ION_TYPE + ")"
    		, regexType);
    
    	std::smatch match;
    
    	if (std::regex_search(line, match, rx_ionType))
    	{
    		for (int i = 0; i < match.size(); i++)
    		{
    			std::cout << "|" << match.str(i) << "|\n";
    		}
    		
    	}
    	else
    	{
    		std::cout << "No match.\n";
    	}
    }

    {
    	const std::string RX_ION_TYPE("ab?(?:cd|dc)|ab?");
    
    	const auto regexType = std::regex::ECMAScript;
    
    	std::regex rx_ionType;
    
    	rx_ionType.assign(
    		"(" + RX_ION_TYPE + ")"
    		, regexType);
    
    	std::smatch match;
    
    	if (std::regex_search(line, match, rx_ionType))
    	{
    		for (int i = 0; i < match.size(); i++)
    		{
    			std::cout << "|" << match.str(i) << "|\n";
    		}
    		
    	}
    	else
    	{
    		std::cout << "No match.\n";
    	}
	}
	{
		const std::string RX_ION_TYPE("ab?(?:cd|dc)?");

		const auto regexType = std::regex::ECMAScript;

		std::regex rx_ionType;

		rx_ionType.assign(
			"(" + RX_ION_TYPE + ")"
			, regexType);

		std::smatch match;

		if (std::regex_search(line, match, rx_ionType))
		{
			for (int i = 0; i < match.size(); i++)
			{
				std::cout << "|" << match.str(i) << "|\n";
			}

		}
		else
		{
			std::cout << "No match.\n";
		}
	}

	return 0;
}
