简体   繁体   English

如何从 substring 中删除 Substring 开始直到 Java 中的字符串结尾

[英]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.我有一个使用 RestAssured 的方法来建立不记名令牌并建立详细的 cookies,我需要将其包含在其他 API 端点的请求标头中。

When I call cookies.getDetailedCookies.toString() I get the below (where cookies variable represents Rest Assured Http Cookie): 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 " "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=/;安全;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. 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): 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):

在此处输入图像描述

Is there a way to remove this particular cookie using java Starting with BIG* until the end of the string?有没有办法使用 java 从 BIG* 开始直到字符串结尾来删除这个特定的 cookie?

If you want to remove string from BIG.. to end of String, you can simply do this:如果你想从BIG..中删除字符串到字符串的结尾,你可以简单地这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM