For example:
std::string filename{ "my_file01010_asset_103.csv" };
std::regex re( R"((\d+)\.)" );
std::smatch m;
if( std::regex_search( filename, m, re ) )
{
std::string number = m[1].str( );
std::cout << number << std::endl;
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have:
std::string filename{"my_file01010_asset_103.csv"};
try
{
std::cout << std::regex_replace(filename,
std::regex("[^0-9+]"), "") << std::endl;
}
catch (std::exception& ex)
{
std::cerr << ex.what();
}
How can I extract 103
only?
For example:
std::string filename{ "my_file01010_asset_103.csv" };
std::regex re( R"((\d+)\.)" );
std::smatch m;
if( std::regex_search( filename, m, re ) )
{
std::string number = m[1].str( );
std::cout << number << std::endl;
}