The follwoing example, will demonstrates, how find string wich starts with Uppercase letter using regular expressions
package com.onlinecodegeek.java;import java.util.regex.Matcher;import java.util.regex.Pattern;/** * @author tponnam * */public class FindFirstUpperCaseLetterInStringEx { /** * @param args */ public static void main(String[] args) { String content = "welcome to Awesome Java world and Hello Scout"; findUppercaseFirstLetterInString(content); } private static void findUppercaseFirstLetterInString(String content) { Matcher m = Pattern .compile("([a-z])([a-z]*)", Pattern.CASE_INSENSITIVE).matcher( content); System.out.println("Given input string : " + content); while (m.find()) { if (m.group(1).equals(m.group(1).toUpperCase())) { System.out.println("First Letter Upper case match found :" + m.group()); } } }}| Given input string : welcome to Awesome Java world and Hello Scout First Letter Upper case match found :Awesome First Letter Upper case match found :Java First Letter Upper case match found :Hello First Letter Upper case match found :Scout |

0 comments :
Post a Comment