1

Example my string have :

text = " Hi {fullname}, wellcome u join my group"

this is my code:

text = text.replaceAll("\\{fullname\\}", user.getMobile() != null ? user.getMobile() : "");

but now i have problem if {fullname} is {FULLNAME} or {Fullname} or {fuLLname}, i cant find exactly what i want and replace it. Anyone have a solution please help me! Thanks

3 Answers 3

3

You can use (?i) as a prefix of your token "fullname" which will make it case insensitive so it will work for any Upper and Lower case combination of your token "fullname" "{FULLname} , {fullNAME} , {FulLName} ,{fuLLname}"

text = text.replaceAll("\\{(?i)fullname\\}", user.getMobile() != null ? user.getMobile() : "");
Sign up to request clarification or add additional context in comments.

Comments

2

ReplaceAll takes regex, so you can try (?i) ignorecase in regex

text = text.replaceAll("\\{(?i)fullname\\}", us...

That works for all {fullname} , {FULLNAME} , {Fullname} ,{fuLLname}

Comments

-1

Try using this

    String ans="Hi {fullname}, wellcome u join my group";

    ans = ans.replaceAll("\\{[a-zA-Z]*\\}", "ANYTHING");

    System.out.println(ans);

Comments

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.