c++ – How would I use regex to ignore multiple parenthesis inside a string?

Since I try to avoid Regex when possible, here is an example of using substr:

std::size_t endPos = str.find("),"); //gets the end of the inner parentheses
std::string sub = str.substr(8, endPos - 8); //substrings to pull inner string out

I don’t know how you are reading these strings in, but here is a full example to just dump out the provided samples:

#include <iostream>
#include <vector>

int main()
    std::vector<std::string> vs;

    std::string s1 = "INSERT((AIRBUS,A340,295,137), PlaneType)";
    std::string s2 = "INSERT((1050,Meal,N), Flight)";
    std::string s3 = "INSERT((1050,10/5/2021,1/1/2021,19:20,1/1/2002,20:40,8.0), FlightLegInstance)";
    std::string s4 = "INSERT((SEA,Seattle,WA), AirPort)";


    for (int i = 0; i < vs.size(); i++) {
        std::size_t endPos = vs[i].find("),");
        std::string sub = vs[i].substr(8, endPos - 8);
        std::cout << sub << std::endl;

Read more here: Source link