Reputation: 111
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
Upvotes: 1
Views: 186
Reputation: 322
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() : "");
Upvotes: 3
Reputation: 91
Try using this
String ans="Hi {fullname}, wellcome u join my group";
ans = ans.replaceAll("\\{[a-zA-Z]*\\}", "ANYTHING");
System.out.println(ans);
Upvotes: -1
Reputation: 121998
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}
Upvotes: 2