Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
一重ダッシュ (-) または二重ダッシュ (--) またはスペース文字 (\s) で分割される分割関数の正規表現を作成しようとしています。「[-\\s]」を試していますが、二重ダッシュに当たると余分な空の文字列が返されます。
"12-34 56--7 89".split("[-\\s]"); 戻り値
12 34 56 7 89
次のようなものを試すことができます:
"[-\\ ]+"
例 :
String str = "12-34 - 56--7 89"; String[] arraySplit = str.split("[-\\ ]+"); for (String s : arraySplit){ System.out.println(s); }
結果 :