Java examples for Regular Expressions:Word
Starts And End With Capital using regex
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { String inputStr = "this is a TEST tesT Test"; String[] stringArray = inputStr.split(" "); for (String s : stringArray) { String regex = "\\b[A-Z][a-zA-Z]*[A-Z]\\b"; // String regex = "([A-Z]\\w*[A-Z])"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(s); boolean found = matcher.find(); if (found) { System.out.println(matcher.group()); }//from w w w . j a v a2 s. c o m } } }