I want to format the line:
10% go to school, which is free of charge.
and get the following output:
About 90 percent of all schools and schools that are free ...
It turned out to replace the first letter in the expression with a big one, I can not figure it out anymore. Code:
private static final String STRING = "about 90 percent of all children attend public school, which is free ... the other 10 percent go I private schools,Which often include religious education."; private static final String REGEX = "(?:^| )^[az]"; public static void main(String[] args){ Matcher matcher = Pattern.compile(REGEX).matcher(STRING); StringBuffer stringBuffer = new StringBuffer(); while (matcher.find()){ matcher.appendReplacement(stringBuffer, matcher.group().toUpperCase()); } matcher.appendTail(stringBuffer); System.out.println(stringBuffer.toString()); }