Hey all. I'll make this quick. I want to search for a pattern and replace it with an empty string using the boost/curl libraries OR strictly c++.. No DotNet.

The below code I have, removes HTML Tags from a file/string:

static string StripTags(string source)
{
    int iSize = (int)source.length();
    char StrData[iSize];
	int arrayIndex = 0;
	bool inside = false;

	for (int i = 0; i < iSize; i++)
	{
	    char let = source[i];
	    if (let == '<')
	    {
            inside = true;
            continue;
	    }
	    if (let == '>')
	    {
            inside = false;
            continue;
	    }
	    if (!inside)
	    {
            StrData[arrayIndex] = let;
            arrayIndex++;
	    }
	}
     return StrData;
    //return new string(StrData, 0, arrayIndex);     //DOES NOT WORK?! Don't know why..
}

But that leaves HUGE white spaces in the file where the HTML tags were..

Then I tried this, but got stuck because the code I had previously never worked even though it said pattern found.. It also said "Ran out of stack space..":

string preg_match_all(const string WebData)
{
    boost::regex expression("<(.|\n)*?>");

    try
    {
        if(boost::regex_match(WebData, expression))
        {
            cout<<"Match Found.. Replacing with Empty String";
            boost::regex_replace(WebData, expression, "");
        }
        else
            cout<<"Match Not Found";
    }
    catch(exception &e)
    {
        cout<<e.what();
    }
    return WebData;
}

The PHP Code I'm trying to emulate with C++...

preg_match_all("|<td(.*)</td>|U",$table,$rows);
 
foreach ($rows[0] as $row){
	if ((strpos($row,'<th')===false)){
 
		preg_match_all("|<td(.*)</td>|U",$row,$cells);

		$number = strip_tags($cells[0][0]);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.