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.
正規表現を行う方法、すべての空白、ハイフン、セミコロンで文字列を分割する方法について疑問があります。これは Java にあります。私がやっている:String[] tmp = input.nextLine().split("\\s:-");
String[] tmp = input.nextLine().split("\\s:-");
しかし、それは機能していません。正しい方法はどれですか?
あなたは現在、3 つすべてを続けて分割しています。選択から任意の 1 つを選択する文字クラスを試してください。
String[] tmp = input.nextLine().split("[\\s:\\-]");
(ハイフンは文字クラスで意味があるため、ハイフンもエスケープする必要があります。)