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 メソッド ReplaceAll を使用して、数字の前の空白を置き換えたいですか? 正規表現を作成するにはどうすればよいですか?
次に例を示します。
変わりたい:
John 9:50 Steve 12:30 Luke Peter 14:44
に:
John\t9:50 Steve\t12:30 Luke Peter\t14:44
誰もこれを提案していません:
str = str.replaceAll("\\s+(?=\\d)", "\\t");
これにより、数字の前にある任意の数の空白文字がタブ文字に置き換えられます。
他の回答はすべて、数字の前の最後の空白のみを置き換えるため、最終的な文字列に複数のタブが含まれる可能性があります。