Tuesday, September 18, 2012

Extract place holders from an error message

String errMsg = "{1} and {2} values can't be same!!!";
Pattern pattern = Pattern.compile("\\{[1-9]+\\}");
Matcher matcher = pattern.matcher(errMsg);
       
while(matcher.find()){
   System.out.println(matcher.group());
}

Output:
{1}
{2}