import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(.*?(cardNumber|card.number|number|cvc|cvv|cardVerificationCode|card_Verification_Code|cardVerificationValue|card_Verification_Value|expireMonth|expireYear|x-api-key|apiKey)[\\\\\\\\\\\"]*:[ \\\\[\\n\\\\\\\\\\\"\\\\]]*)[a-zA-Z0-9$&+,:;=?@#|\\'<>.^*()%!-]+(.*?)";
final String string = "{\"cardNumber\": \"34be18a5-f710-45ba-9b4d-0c13c9b07c7e\", \"http_method\": \"POST\", \"url\": \"https://api.qabakuun.cloud/ratedockAPI/RDK259/booking\", \"headers\": {\"User-Agent\": \"python-requests/2.28.1\", \"Accept-Encoding\": \"gzip, deflate\", \"Accept\": \"application/json\", \"Connection\": \"keep-alive\", \"Content-Type\": \"application/json\", \"Content-Length\": \"1791\"}, \"body\": {\"username\": \"rhcp@secretescapes.com\", \"password\": \"BbiqzYuP\", \"partnerId\": \"RDK259\", \"partnerName\": \"SecretEscapes\", \"action\": \"getBooking\", \"hotelReservation\": [{\"hotelCode\": \"TESTRATEDOCKHOTEL\", \"hotelName\": \"Test Ratedock Hotel\", \"resStatus\": \"New\", \"checkIn\": \"2022-10-10\", \"checkOut\": \"2022-10-12\", \"paymentMethod\": \"BANK\", \"rateType\": \"BAR\", \"currencyCode\": \"GBP\", \"totalAdult\": \"1\", \"totalChild\": \"0\", \"child_ages\": [], \"totalBaby\": \"0\", \"baby_ages\": [], \"roomStays\": [{\"roomTypeId\": \"TESTRATEDOCKROOMTYPE\", \"roomName\": \"Test Ratedock Room Type\", \"roomType\": \"Daily Room\", \"numberOfUnits\": \"1\", \"adultCount\": \"1\", \"childCount\": \"0\", \"child_ages\": [], \"babyCount\": \"0\", \"commission\": \"0.00\", \"roomIndex\": \"1\", \"ResGuestRPH\": \"1\", \"bookingPerDayPrices\": [{\"dateYmd\": \"2022-10-10\", \"price\": \"184.90\", \"ratePlanId\": \"TESTRATEDOCKRATEPLAN\", \"cancelPolicy\": \"\"}, {\"dateYmd\": \"2022-10-11\", \"price\": \"159.60\", \"ratePlanId\": \"TESTRATEDOCKRATEPLAN\", \"cancelPolicy\": \"\"}], \"total\": {\"amountAfterTaxes\": \"344.50\", \"amountBeforeTaxes\": \"344.50\"}, \"roomIncServices\": []}], \"guestDetails\": [{\"ResGuestRPH\": \"1\", \"firstName\": \"(redacted)\", \"lastName\": \"(redacted)\", \"middleName\": \"\", \"email\": \"test+uk@secretescapes.com\", \"phone\": \"123123123\", \"address\": \"\", \"country\": \"\"}], \"Comment\": {\"Text\": \"\"}, \"paymentCard\": {\"cardHolderName\": \"\", \"cardType\": \"\", \"cardCategory\": \"\", \"cardNumber\": \"\", \"ExpiryMonth\": \"\", \"ExpiryYear\": \"\", \"StartDayMonth\": \"\", \"StartDayYear\": \"\", \"IssueNum\": \"\", \"seriesCode\": \"\", \"vccCurrencyCode\": \"\", \"vccBalance\": \"\", \"vccDeactivationDate\": \"\", \"vccActivationDate\": \"\"}, \"totalCharge\": [{\"taxDetails\": {\"typeTax\": \"\", \"includes\": \"\", \"taxPrice\": \"\", \"taxDetails\": \"\"}, \"priceDetails\": [{\"rateType\": \"BAR\", \"amountAfterTaxes\": \"344.50\", \"amountBeforeTaxes\": \"344.50\"}]}]}]}}";
final String subst = "$1***$2";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceFirst(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html