Hello,
The solution is to take the problem in reverse: instead of cutting the string according to certain criteria, it would be wise to find items in the chain.
I understand that I see 3 things to look for
1) Mathematical symbols: (+*/-)
2) Figures
3) The strings (short, everything except the above).
What I translate into this:
Code:
Final String symbols = "[+-/*()]"; / / A character from the following: + - * / ()
Final String numbers = "\\d + (\\.\\d *)? "; / / Numbers: at least one number, possibly followed by '. " and optional data
Final String string = "[^+-/*()\\d] + "; / / A string: All who are no numbers or symbols
Then just look for these items:
Code:
String input = "(Other receivables + Accounts receivable) / 5.25 * ARRESTED IN NV + Shipping preliminary";
Pattern pattern = Pattern.compiles("("+ + symbols")|("numbers + +")|("+ + strings")");
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
System.out.System.out.println("Found: [" + Matcher.group() + "]");
}
Now if your need is more complex it will probably define a grammar and use a parser generator such as Javac.
Bookmarks