split a string based on pattern in java - capital letters and numbers
- by rookie
Hi all
I have the following string "3/4Ton". I want to split it as --
word[1] = 3/4 and word[2] = Ton.
Right now my piece of code looks like this:-
Pattern p = Pattern.compile("[A-Z]{1}[a-z]+");
Matcher m = p.matcher(line);
while(m.find()){
System.out.println("The word --> "+m.group());
}
It carries out the needed task of splitting the string based on capital letters like:-
String = MachineryInput
word[1] = Machinery , word[2] = Input
The only problem is it does not preserve, numbers or abbreviations or sequences of capital letters which are not meant to be separate words. Could some one help me out with my regular expression coding problem.
Thanks in advance...