Yang Rui Yang Rui - 4 months ago 8
Java Question

how to split this with regex

i want to split a string:


1day2hour3minute,


into following array:


[1day,2hour,3minute]


i use split("day|hour|minute"),got this

[1,2,3]

how to handle?thanks!

Answer

Try this

String res = Arrays.toString("1day2hour3minute".split("(?<=(day|hour|minute))"));
System.out.println(res);