java: words extract the capital letter out

java, regex

Solution

You can try replaceAll

String text2 = text.replaceAll("[^A-Z]", "");

As @Vic comments, to include all English/Non-English Capital letters.

String text2 = text.replaceAll("[^\p{Lu}]", "");

Problem

how to extract the capital letter out of words using java? ``` example: enter your words:Hello I Am Heyman output:HIAH ``` thank

Original source