Search code examples
javacookiesreplacesubstringrest-assured

How to remove Substring from substring start until the end of the string in Java


I have a method using RestAssured that establishes the bearer token and it establishes the detailed cookies that I need to include in request headers for other API endpoints.

When I call cookies.getDetailedCookies.toString() I get the below (where cookies variable represents Rest Assured Http Cookie):

"amlbcookie=01;Path=/;Domain=mydomain.com;Secure;HttpOnly tvgauthcookie=C6nl2pVadONSclRAaL1gxWd2-60.AAJTSQACMDYAAlNLABxFOTFSWk1nUW9Td1NJOHhrSHppUW1FUHdKdG89AAR0eXBlAANDVFMAAlMxAAIwMQ..;Path=/;Domain=mydomain.com;Secure;HttpOnly BIGipServerqavgamws-https-pool=1234567890.12345.0000;Path=/;Secure;HttpOnly"

One problem is that in Postman when I add the bearer token in Authorization header, it automatically gets the necessary cookies and is shown in the Cookie header as seen below. I am not seeing the BIGipServerqavgamws-https-pool=1234567890.12345.0000;Path=/;Secure;HttpOnly in the Postman Cookie header value (I suppose it is a browser session cookie which is not needed for submitting the request via Postman):

enter image description here

Is there a way to remove this particular cookie using java Starting with BIG* until the end of the string?


Solution

  • If you want to remove string from BIG.. to end of String, you can simply do this:

    String cookies = ...;
    String sub = cookies.replaceAll(" BIG(.+)", ""); //also remove white space before BIG
    //System.out.println(sub);