Java 标记化后列表中的空格

Java 标记化后列表中的空格,java,tokenize,Java,Tokenize,我有一个单词列表,在标记化之后,我在列表中得到了一些我实际上不想要的空白。建议请 样本串 String str = "3) type an \"l\" in the search field (\"bl\")"+ "4) startHistorySearch()'s previous result contains [\"blah\", \"baaa\", \"bloop\", \"bzzz\"], Satchel filters this down to [\"blah\", \"bloop\

我有一个单词列表,在标记化之后,我在列表中得到了一些我实际上不想要的空白。建议请

样本串

String str = "3) type an \"l\" in the search field (\"bl\")"+
"4) startHistorySearch()'s previous result contains [\"blah\", \"baaa\", \"bloop\", \"bzzz\"], Satchel filters this down to [\"blah\", \"bloop\"] to match the new \"bl\" search string"+
and so on.....
下面是代码和输出片段

String[] splitString = (EXAMPLE_TEST.split("[\\[\\],\\'\"  \\(\\)\\{\\}\\*\\.]"));
输出

nsIAutoCompletResult, , no, , Simple, , , , so, the, QI, fails, , historyResult
在一些地方我看到这样的

finds, 1, entry, , , blah, , , , search-suggestions, finds, , baaa, , , , bloop, , , , bzzz, , , the, autocompete, menu, shows, these, in, order, with, a, divider, between, , blah, , and, , baaa, , 3, , type, , l, , in, the, search, field, , , bl, , 4, , startHistorySearch, , , s, previous, result, contains, , , blah, , , , baaa, , , , bloop, , , , bzzz, , , , Satchel, filters, this, down, to, , , blah, , , , bloop, , , to, match, the, new, , bl, , search, string5, , nsSearchSuggestions, s, onReadyState, , , change, is, called, with, updated, search,

只需在表达式中添加一个
+
,以避免在两个标记之间分割。您还可以稍微简化表达式,不必转义字符类中的所有字符:

String[] splitString = (EXAMPLE_TEST.split("[\\[\\],'\" (){}*.]+"));

只需在表达式中添加一个
+
,以避免在两个标记之间分割。您还可以稍微简化表达式,不必转义字符类中的所有字符:

String[] splitString = (EXAMPLE_TEST.split("[\\[\\],'\" (){}*.]+"));

再次迭代并删除修剪后长度为零的任何内容。再次迭代并删除修剪后长度为零的任何内容。