0

I have the below java string in the below format.

externalCustomerID: { \"custToken\": \"xyz\" }

I want to extract xyz value from above string. can anyone suggest me any regex expression for that in java?

3
  • is this the string "custToken": "xyz" or it's externalCustomerID: { "custToken": "xyz" } Commented Aug 18, 2021 at 6:31
  • externalCustomerID: { "custToken": "xyz" } this is my input string Commented Aug 18, 2021 at 6:33
  • you can use JSONParser to read the value. Go through below link to understand more about the JSONParser. stackoverflow.com/questions/2591098/how-to-parse-json-in-java Commented Aug 18, 2021 at 6:35

1 Answer 1

1

check this one

        Pattern pattern = Pattern.compile("(\\w+: \\{ \"\\w+\": \")(\\w+)");

    Matcher matcher = pattern.matcher("externalCustomerID: { \"custToken\": \"xyz\" }");

    if (matcher.find()) {
        System.out.println(matcher.group(2));
    }
Sign up to request clarification or add additional context in comments.

2 Comments

you welcome :) you can use this site to test and verify your regex regex101.com make sure to choose java flavor from the left side
sorry @user16320675 it did not get what you mean

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.