How to determines if a string starts with uppercase letter

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());
}
}
}
}
Output
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

 


Thulasiram P

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Thulasiram P

Follow Me @Google+
SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment