split a string based on pattern in java - capital letters and numbers

Posted by rookie on Stack Overflow See other posts from Stack Overflow or by rookie
Published on 2010-05-17T15:41:26Z Indexed on 2010/05/17 16:20 UTC
Read the original article Hit count: 377

Filed under:
|
|
|

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...

© Stack Overflow or respective owner

Related posts about java

Related posts about regex