1package com.tutorialspoint;
2
3import java.lang.*;
4
5public class StringDemo {
6
7 public static void main(String[] args) {
8
9 String str = "a d, m, i.n";
10 String delimiters = "\\s+|,\\s*|\\.\\s*";
11
12 // analyzing the string
13 String[] tokensVal = str.split(delimiters);
14
15 // prints the number of tokens
16 System.out.println("Count of tokens = " + tokensVal.length);
17
18 for(String token : tokensVal) {
19 System.out.print(token);
20 }
21 }
22}
1Pattern p = Pattern.compile("(\\d+)|([a-zA-Z]+)");
2Matcher m = p.matcher("810LN15");
3List<String> tokens = new LinkedList<String>();
4while(m.find())
5{
6 String token = m.group( 1 ); //group 0 is always the entire match
7 tokens.add(token);
8}
9//now iterate through 'tokens' and check whether you have a number or text