Substring erase with certain pattern For following input string:

"VISITOR_INFO1_LIVE=USv90B-7CzI; LOGIN_INFO=e486e37a395be3f0e3b3237d090a6829c1oAAAB7IjQiOiAiREVMRUdBVEVEIiwgIjciOiAwLCAiMSI6IDEsICIzIjogMjAxMTk0MTMwNiwgIjgiOiA2MDgwMTg0NTEzNjQsICIxMCI6IDIzOTYyMTEyODczNH0=; PREF=f5=30;HSID=AHuJQBOVR0lQoRt_3; APISID=QaParXGsQcEPCzKg/A1smCfYrfMjxvfEPT; YSC=Vm3Amq5loFM";


I want to remove all the patterns that contains *SID (HSID,APISID here) upto ';'. I also want to remove substring "LOGIN_INFO= ....;"

So, output string should be:


"VISITOR_INFO1_LIVE=L80EDuHCEF8; PREF=f5=30";`



 const char *str ="VISITOR_INFO1_LIVE=USv90B-7CzI; LOGIN_INFO=e486e37a395be3f0e3b3237d090a6829c1oAAAB7IjQiOiAiREVMRUdBVEVEIiwgIjciOiAwLCAiMSI6IDEsICIzIjogMjAxMTk0MTMwNiwgIjgiOiA2MDgwMTg0NTEzNjQsICIxMCI6IDIzOTYyMTEyODczNH0=; PREF=f5=30;HSID=AHuJQBOVR0lQoRt_3; APISID=QaParXGsQcEPCzKg/A1smCfYrfMjxvfEPT; YSC=Vm3Amq5loFM"; 
 char *Cookie = NULL;
 cout &lt;&lt; "original string is:\n" &lt;&lt; str &lt;&lt; "\n";
 int len = strlen(str)+1;
 cout &lt;&lt; "length of original string is : " &lt;&lt; len &lt;&lt; "\n";
 Cookie = new char[strlen(str)];
 strncpy(Cookie,str,len);

 char *p1 = strstr(Cookie,"LOGIN_INFO");
 char *p2 = NULL;
 if(p1){
      p2 = strstr(p1,";")+1;
      while(*p2 == ' ') p2++;
 }
 if(p1 &amp;&amp; p2)
      memmove(p1,p2,strlen(p2)+1);

 char *ID = strstr(Cookie,"SID"); 
 while( ID != NULL){
      char *start_pos = NULL, *end_pos = NULL;    
      while((*ID != ';') &amp;&amp; (*ID != Cookie[0]) &amp;&amp; (*ID != ' ')){
           --ID;
      }
      if(*ID == Cookie[0]) start_pos = ID;
      else start_pos = ID+1;
      end_pos = strstr(start_pos,";")+1;
      while(*end_pos == ' ')
           end_pos++;
      memmove(start_pos,end_pos,strlen(end_pos)+1);                                   
    //  } 
      /*else
           std::cout &lt;&lt; "does not find substr " &lt;&lt; "\n";*/

    //  cout &lt;&lt; "modified string is :" &lt;&lt; Cookie &lt;&lt; "\n";
      ID = strstr(Cookie,"SID");
 }
      //cout &lt;&lt; "final modified string is : " &lt;&lt; Cookie &lt;&lt; "\n";
 char *Cookie_modified = NULL;
 const char *pch = strstr(Cookie,"PREF");
 if(pch != NULL){
      const char *append = "&amp;f2=8000000";
      int len = strlen(Cookie) + strlen(append) + 1;
      Cookie_modified = new char[len];
      strncpy(Cookie_modified,Cookie,len);
      Cookie_modified[len-1] = '\0';
      char *p = strstr(Cookie_modified,"PREF");
      strncpy(p+(strlen(p)),append,strlen(append));
      cout &lt;&lt; "modified Cookie is : " &lt;&lt; Cookie_modified &lt;&lt; "\n";
  //    cout &lt;&lt; "length of modified cookie is : " &lt;&lt; strlen(Cookie_modified) &lt;&lt; "\n";
 }

 else{
      cout &lt;&lt; "do not find reference: " &lt;&lt; "\n";
      const char *append = ";PERF=f2=8000000";
      int len = strlen(Cookie) + strlen(append) + 1;
      Cookie_modified = new char[len];
      Cookie_modified[len-1] = '\0';
      strcat(Cookie_modified,Cookie);
      strcat(Cookie_modified,append);
      cout &lt;&lt; "case 2: modified Cookie is: " &lt;&lt; Cookie_modified &lt;&lt; "\n";

 }
 delete[] Cookie;
 delete[] Cookie_modified;     
 return 0;
Comment on Question
Can tell if your code matches the problem statement.
Because I can't understand the problem statement.
Input

&quot;VISITOR_INFO1_LIVE=USv90B-7CzI; LOGIN_INFO=e486e37a395be3f0e3b3237d090a6829c1oAAAB7IjQiOiAiREVMRUdBVEVEIiwgIjciOiAwLCAiMSI6IDEsICIzIjogMjAxMTk0MTMwNiwgIjgiOiA2MDgwMTg0NTEzNjQsICIxMCI6IDIzOTYyMTEyODczNH0=; PREF=f5=30;HSID=AHuJQBOVR0lQoRt_3; APISID=QaParXGsQcEPCzKg/A1smCfYrfMjxvfEPT; YSC=Vm3Amq5loFM&quot;;

Output

&quot;VISITOR_INFO1_LIVE=L80EDuHCEF8; PREF=f5=30&quot;;

Questions

Is the first and last quote and the last semi colon part of the input or just your formatting?
*SID (HSID,APISID here) upto ';'
I see none of these things in the output. there is no SID no HSID no APISID
Whey is  'VISITOR_INFO1_LIVE' in the output?
It is not specified as something you want in the output.
Why is PREF in the output.
This PREF=f5=30 seems like an illegal parameter. is = allowed in the parameter.

Review of code
OK. I assume there is a function wrapper here that defines str!! What is the type of str? I am going to assume char const* as you seem to be coding using C (rather than real C++). Types are super important in C++ please make sure we know all the types of all identifiers.
Why split up the declaration from the initialization?
 char *Cookie = NULL;
 ......
 Cookie = new char[strlen(str)];
 strncpy(Cookie,str,len);
 ......
 delete[] Cookie;

This just gives you the opportunity to misuse Cookie in the code. If you declare and initialize in the same statement then no misuse.
Also C++ code should never contain a delete (especially when you are learning). It should have very few calls (if any calls) to new. Dynamic memory management should be controled via an object. This is usually a smart pointer or a container depending on your usage.
Thirdly why use the C-String API. C++ has its own string that handles memory management for you and does a better job. Currently your code is not exception safe. An exception thrown in your code will result in leaked memory.
Thirdly you actually did it wrong and did not allocate enough space (you forgot to allocate space for the '\0' character that terminates a C-String). I know you used the strncpy to compensate for this. But all the other string functions are expecting it so something is likely to go wrong.
Forgot to check the result of a string function.
      p2 = strstr(p1,&quot;;&quot;)+1;

If strstr() returns NULL then we add 1 to it and now it is no longer NULL and your next test will always work. Even if it is not supposed too.
Are you sure the second test id correct?
      while((*ID != ';') &amp;&amp; (*ID != Cookie[0]) &amp;&amp; (*ID != ' ')){
           --ID;
      }

I think you are testing here *ID != Cookie[0] to make sure that you don't fall off the front of the string. But you are checking the content of the characters not the position of the pointers. A better test is (ID &gt; Cookie)