Java parsing error

I tried to parse the line:

Portfolio1 [{Exchange: NASDAQ-Symbol: INFY-Full Name: Infosys Technologies Limited (ADR) -Account rate: 100.0 percent profit: 388.2258065 -Location Information: 1240.0 USD -This position taken today: -46.9997 USD - This position has a total profit of: 4814.0 USD -This position costs: 6054.0 USD} - {Exchange: NASDAQ-Symbol: GOOG-Full Name: Google Inc.-Share Count: 10.0-Percent Gain: 17.98444444-Position value: 4500.0 USD -This position taken today: -10.70007 USD -This position has a total profit of: 809.3 USD - This position costs: 5309.3 USD} - {Exchange: NASDAQ-Symbol: QCOM-Full Name: QUALCOMM, Inc.-Share Count: 0.0-Percent Gain: 0.0} -] Portfolio2 [{Exchange: NASDAQ-Symbol: GOOG-Full Name: Google Inc.-Share Count: 1000.0-Percent Gain: 32.56679151-Cost by Position: 400500.0 USD -This position was taken today: -1070.007 USD-This position has a total profit: 130430.0 USD -This position costs: 530930.0 USD} - {Exchange: NASDAQ-Symbol: MSFT-Full Name: Microsoft Corporation-Share: 10.0-Percent Gain: -4.03125. The cost of the position is: 320.0 USD - This position was made today: -2.93001 USD-This position has a total profit of -12.9 USD - This position costs: 307.1 USD} - {Exchange: NYSE-Symbol: IBM-Full Name: International Business Machines Corp.-Share Count: 10.0-Percent Gain: 397.80769230000004-Estimated cost: 260.0 USD-This position taken today: -10.30014 USD-This position has a total profit of: 1034.3 USD-This position is worth: 1294.3 USD} - - {Exchange: NASDAQ-Symbol: NVDA-Full Name: NVIDIA Corporation-Share Count: 100.0-Percent Gain: -10.79418345 - Position Cost: 1788.0 USD. This position was taken today: -70.0 USD. This position has a total profit of:-193.0 USD-This position is worth: 1595.0 USD} -] ";

[

String delims = "[";
String[] tokens = s.split(delims);

for (int i = 0; i < tokens.length; i++)
    System.out.println(tokens[i]);

java.util.regex.PatternSyntaxException: Unclosed character class near index 0 [
+3
2

[ .

String delims = "\\["; String[] tokens = s.split(delims);
+8

, , .

StringTokenizer, , , . , regex split.

StringTokenizer tok=new StringTokenizer(s, "[");
List<String> tokens=new ArrayList<String>();
while (tok.hasMoreTokens()){
   tokens.add(tok.nextToken());
}
+1

Source: https://habr.com/ru/post/1743555/


All Articles