Split in java is separated by ".", "\", "|"

In today's project, I encountered "." , "\", "|" to separate the string, directly using ".", "\", "|" can not be divided, because ".", "\", "|" are Special characters need to be escaped, "\\.", "\\", "\\|".

1 String goodsStr="100: said: test 1|10: yes: test 2" ;
 2 String[] goodList = goodsStr.split("|");

after escaping

String goodsStr="100: Said: Test 1|10: Yes: Test 2" ;
String[] goodList = goodsStr.split("\\|");

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324592945&siteId=291194637